tags:

views:

60

answers:

1

I'm having trouble figuring out how to call a method from a parent module in a class.

I want to call module functions from parent module in my nested classes, but can't seem to find a way how to do this.

example:

module Awesome
  class Checker
    def awesome?
      awesome_detection
    end
  end

  module_function
  def awesome_detection
    true
  end

end

If I call Awesome::Checker.new.awesome?, it's unaware of awesome_detection

Any ideas on what I'm missing?

+3  A: 
#!/usr/bin/env ruby -wKU

module Awesome

  class Checker
    def awesome?
      Awesome.awesome_detection
    end
  end

  def self.awesome_detection
    puts "yes"
  end

end

Awesome::Checker.new.awesome?
# => yes
Simone Carletti