Method: Thor::Base::ClassMethods#from_superclass

Defined in:
lib/thor/base/class_methods.rb

#from_superclass(method, default = nil) ⇒ Object (protected)

Retrieves a value from superclass. If it reaches the baseclass, returns default.



583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/thor/base/class_methods.rb', line 583

def from_superclass(method, default = nil)
  if self == baseclass || !superclass.respond_to?(method, true)
    default
  else
    value = superclass.send(method)

    # Ruby implements `dup` on Object, but raises a `TypeError`
    # if the method is called on immediates. As a result, we
    # don't have a good way to check whether dup will succeed
    # without calling it and rescuing the TypeError.
    begin
      value.dup
    rescue TypeError
      value
    end

  end
end