« Back to Index

Access Instance and Class level methods (one example using new)

View original Gist on GitHub

Access Instance and Class level methods.rb

class Foo
  protected

  def self.hello
    "world"
  end
end

class Bar < Foo
  def self.speak
    puts hello
  end
  
  def speak
    puts hello
  end

  private

  def hello
    self.class.superclass.method(:hello).call
  end
end

b = Bar.new
b.speak   # => "world"
Bar.speak # => "world"