Skip to content

Instantly share code, notes, and snippets.

@jcarouth
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcarouth/5254125eb0e75244339f to your computer and use it in GitHub Desktop.
Save jcarouth/5254125eb0e75244339f to your computer and use it in GitHub Desktop.
class Character
attr_accessor :name
def initialize(attributes = {})
attributes.each do |attr, value|
setter = "#{attr}="
send(setter, value) if self.respond_to?(setter)
end
end
end
characters = %w(Joe Bob Guido).inject([]) do |arr, name|
arr << Character.new(:name => name)
end
puts characters.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment