Skip to content

Instantly share code, notes, and snippets.

@pasberth
Created November 8, 2011 06:22
Show Gist options
  • Select an option

  • Save pasberth/1347149 to your computer and use it in GitHub Desktop.

Select an option

Save pasberth/1347149 to your computer and use it in GitHub Desktop.
プロパティをセットしたりするモジュール
module Propertible
alias propertible_original_method_missing method_missing
def method_missing funcname, *args, &blk
propertible_original_method_missing funcname, *args, &blk
rescue => e
if funcname.to_s =~ /^(.*)\=$/
self.class.send :attr_writer, $1
send :"#{$1}=", args[0]
else
self.class.send :attr_reader, funcname
send funcname
end
end
end
class Person
include Propertible
def initialize name, age
self.name = name
self.age = age
end
end
puts Person.new 'mana', 18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment