Skip to content

Instantly share code, notes, and snippets.

@mungruby
Created May 1, 2012 20:42
Show Gist options
  • Save mungruby/2571199 to your computer and use it in GitHub Desktop.
Save mungruby/2571199 to your computer and use it in GitHub Desktop.
Including a Module in a Struct
module Greeter
def greet
puts "Hello #{name}! You're a #{party}."
end
end
members = %w[name party]
customer = Struct.new('Customer', *members) do
include Greeter
end
customers = []
customers << customer.new("Joe Biden", "barrel of laughs")
customers << customer.new("Barak Obama", "Democrat")
customers.each(&:greet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment