Skip to content

Instantly share code, notes, and snippets.

@oki
Created March 3, 2009 11:11
Show Gist options
  • Select an option

  • Save oki/73286 to your computer and use it in GitHub Desktop.

Select an option

Save oki/73286 to your computer and use it in GitHub Desktop.
module AutoParams
def auto_set(params={})
params.each_pair do |key,value|
self.instance_eval("@#{key} = '#{value}'")
end
end
end
class Human
attr_reader :first, :last
include AutoParams
def initialize(params={})
auto_set(params)
end
end
d = Human.new(:first => 'Michal', :last => 'Kurek')
pp d.inspect
# "#<Human:0x168aa50 @first=\"Michal\", @last=\"Kurek\">"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment