mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
avoid generating iv name each time in accessors
This commit is contained in:
+5
-3
@@ -2,14 +2,16 @@ class Module
|
||||
# 15.2.2.4.13
|
||||
def attr_reader(*names)
|
||||
names.each{|name|
|
||||
define_method(name){self.instance_variable_get('@'+name.to_s)}
|
||||
name2 = ('@'+name.to_s).intern
|
||||
define_method(name){self.instance_variable_get(name2)}
|
||||
}
|
||||
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.to_s,v)}
|
||||
name2 = ('@'+name.to_s).intern
|
||||
name = (name.to_s+"=").intern
|
||||
define_method(name){|v|self.instance_variable_set(name2,v)}
|
||||
}
|
||||
end
|
||||
# 15.2.2.4.12
|
||||
|
||||
Reference in New Issue
Block a user