Created
October 23, 2011 15:21
-
-
Save mungruby/1307469 to your computer and use it in GitHub Desktop.
Initializing a Struct with a block
This file contains 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
describe "Struct", "Struct.new" do | |
context "initializing with a block" do | |
it "should support the implementation defined in the block" do | |
Struct.new("Person", :name, :gender, :age) do | |
def to_s | |
"Hi! My name is #{name} and I am a #{age} year old #{gender}." | |
end | |
end | |
fred = Struct::Person.new("Fred", "male", 50) | |
fred.to_s.should == "Hi! My name is Fred and I am a 50 year old male." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment