Module: NameMagic::ClassMethods
- Defined in:
- lib/y_support/name_magic.rb
Instance Method Summary collapse
-
#new(*args, &block) ⇒ Object
In addition to ‘constant magic’ ability (name upon constant assignment), NameMagic redefines class method #new so that it eats parameter :name, alias :ɴ, and takes care of naming the instance accordingly.
-
#new!(*args, &block) ⇒ Object
Calls #new in avid mode (name_avid: true).
Instance Method Details
#new(*args, &block) ⇒ Object
In addition to ‘constant magic’ ability (name upon constant assignment), NameMagic redefines class method #new so that it eats parameter :name, alias :ɴ, and takes care of naming the instance accordingly. Option :name_avid can also be supplied (true/false), which makes the naming avid if true. (Avid, or aggresive naming means that the instance being named overwrites whatever was stored under that name earlier.)
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/y_support/name_magic.rb', line 341 def new *args, &block oo = args[-1].is_a?( Hash ) ? args.pop : {} # extract hash |
#new!(*args, &block) ⇒ Object
Calls #new in avid mode (name_avid: true).
366 367 368 369 |
# File 'lib/y_support/name_magic.rb', line 366 def new! *args, &block oo = args[-1].is_a?( Hash ) ? args.pop : {} # extract options new *args, oo.merge!( name_avid: true ), &block end |