- An
Objectis a set of instance variables and a pointer to a 'singleton class'. - Properties are looked up in the instance variables, methods are dispatched via the singleton class.
Moduleis a subtype ofObject. AModuleis a set of methods and an ordered list of zero-or-more 'parent' modules.- Module
Abecomes a parent of moduleBviaB.include(A). - Method lookup works by doing a depth-first right-to-left search of a module tree.
Classis a subtype ofModule. AClassis aModulethat can be instantiated.- A
Classhas only one 'superclass'. A class includes its superclass as its first parent module for the purposes of method dispatch. A class's singleton class includes the superclass's singleton class as its first parent. - The default superclass of all classes is
Object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'equalizer' | |
| class EqualizableStruct < Struct | |
| def initialize *args, &block | |
| class << self | |
| include Equalizer.new(*members) | |
| end | |
| super | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # If you don't want to force the composed methods to raise exceptions, | |
| # have them take a block specifying the failure action | |
| def composed_method | |
| frobulate_widgets { return false } | |
| refrobulate_widgets { return false } | |
| confribulate_frobulations { return false } | |
| true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Task : ActiveRecord | |
| { | |
| public string Name { get; set; } | |
| public int AssignedTo_UserId { get; set; } | |
| public DateTime DueOn { get; set; } | |
| public Task() | |
| { | |
| DueOn = DateTime.Now.AddDays(1); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Base | |
| def call | |
| 'call' | |
| end | |
| end | |
| Base.new.call # => "call" | |
| module Override | |
| def new(*) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'virtus' | |
| Point = Struct.new(:x, :y) | |
| class Rectangle | |
| include Virtus | |
| attribute :top_left, Point | |
| attribute :bottom_right, Point |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Share | |
| def call | |
| list.each do |address| | |
| referral = new_referral(address) | |
| # All else being equal, I'd probably prefer a caller-specified | |
| # fallback strategy | |
| referral.save do | |
| @unsaved << referral | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| describe Feeds::Drops::Rss::EntryDrop do | |
| use_vcr_cassette | |
| subject { | |
| Feeds::Drops::Rss::EntryDrop.new(rss_app.feed_entries_to_display[1], context) | |
| } | |
| let(:context) { mock('context') } | |
| let(:rss_app) { |