Class: Class
Instance Method Summary collapse
- #mattr_accessor(*syms, &blk) ⇒ Object (also: #cattr_accessor)
- #mattr_reader(*syms) ⇒ Object (also: #cattr_reader)
- #mattr_writer(*syms) ⇒ Object (also: #cattr_writer)
Instance Method Details
#mattr_accessor(*syms, &blk) ⇒ Object Also known as: cattr_accessor
298 299 300 301 |
# File 'lib/aliyun/oss/extensions.rb', line 298 def mattr_accessor(*syms, &blk) mattr_reader(*syms, &blk) mattr_writer(*syms, &blk) end |
#mattr_reader(*syms) ⇒ Object Also known as: cattr_reader
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/aliyun/oss/extensions.rb', line 250 def mattr_reader(*syms) = syms. syms.each do |sym| raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/ class_eval(<<-EOS, __FILE__, __LINE__ + 1) @@#{sym} = nil unless defined? @@#{sym} def self.#{sym} @@#{sym} end EOS unless [:instance_reader] == false || [:instance_accessor] == false class_eval(<<-EOS, __FILE__, __LINE__ + 1) def #{sym} @@#{sym} end EOS end class_variable_set("@@#{sym}", yield) if block_given? end end |
#mattr_writer(*syms) ⇒ Object Also known as: cattr_writer
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/aliyun/oss/extensions.rb', line 274 def mattr_writer(*syms) = syms. syms.each do |sym| raise NameError.new("invalid attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/ class_eval(<<-EOS, __FILE__, __LINE__ + 1) @@#{sym} = nil unless defined? @@#{sym} def self.#{sym}=(obj) @@#{sym} = obj end EOS unless [:instance_writer] == false || [:instance_accessor] == false class_eval(<<-EOS, __FILE__, __LINE__ + 1) def #{sym}=(obj) @@#{sym} = obj end EOS end send("#{sym}=", yield) if block_given? end end |