Skip to content

Instantly share code, notes, and snippets.

@mungruby
Created October 23, 2011 15:21
Show Gist options
  • Save mungruby/1307469 to your computer and use it in GitHub Desktop.
Save mungruby/1307469 to your computer and use it in GitHub Desktop.
Initializing a Struct with a block
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