diff options
| author | Yukihiro Matsumoto <[email protected]> | 2012-06-20 13:44:32 +0900 |
|---|---|---|
| committer | Yukihiro Matsumoto <[email protected]> | 2012-06-20 13:44:32 +0900 |
| commit | 97e5ab22f66d0b70643ac2b6d76aef55a5122746 (patch) | |
| tree | a926e83e42610dde2bdde03a67ac0b7b8207f357 | |
| parent | ea81146a41d730f951de452ffb9217e2aceba19d (diff) | |
| download | mruby-97e5ab22f66d0b70643ac2b6d76aef55a5122746.tar.gz mruby-97e5ab22f66d0b70643ac2b6d76aef55a5122746.zip | |
add Module#{attr,attr_reader,attr_writer,attr_accessor}; close #257
| -rw-r--r-- | mrblib/class.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/mrblib/class.rb b/mrblib/class.rb new file mode 100644 index 000000000..9c3ef91fd --- /dev/null +++ b/mrblib/class.rb @@ -0,0 +1,24 @@ +class Module + # 15.2.2.4.13 + def attr_reader(*names) + names.each{|name| + define_method(name){self.instance_variable_get(name)} + } + end + # 15.2.2.4.14 + def attr_writer(*names) + names.each{|name| + aset = (name.to_s+"=").intern + define_method(aset){|v|self.instance_variable_set(name,v)} + } + end + # 15.2.2.4.12 + def attr_accessor(*names) + attr_reader(*names) + attr_writer(*names) + end + # 15.2.2.4.11 + def attr(name) + attr_reader(name) + end +end |
