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.)
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/y_support/name_magic.rb', line 347 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).
372 373 374 375 |
# File 'lib/y_support/name_magic.rb', line 372 def new! *args, &block oo = args[-1].is_a?( Hash ) ? args.pop : {} # extract options new *args, oo.merge!( name_avid: true ), &block end |