Skip to content

Instantly share code, notes, and snippets.

@mungruby
Created April 28, 2012 02:08
Show Gist options
  • Save mungruby/2515090 to your computer and use it in GitHub Desktop.
Save mungruby/2515090 to your computer and use it in GitHub Desktop.
Add a method to a Struct
members = %w[NAME ADDRESS]
members.map!(&:downcase)
members.map!(&:to_sym)
Customer = Struct.new(*members) do
def print
puts self.to_a.join(",")
end
end
customers = []
customers << Customer.new("Joe Biden", "Left of Center")
customers << Customer.new("Barak Obama", "Left of Joe Biden")
customers.each(&:print)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment