Skip to content

Instantly share code, notes, and snippets.

@nkbt
Last active April 8, 2018 02:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nkbt/a0df02529c0cb880dd99 to your computer and use it in GitHub Desktop.
Save nkbt/a0df02529c0cb880dd99 to your computer and use it in GitHub Desktop.
module Test
  def get
    y x
  end

  def x
    'x'
  end

  def y arg
    arg + 'y'
  end

  module_function :get
end

puts Test.get
10:31 $ ruby test.rb 
test.rb:3:in `get': undefined local variable or method `x' for Test:Module (NameError)
        from test.rb:18:in `<main>'
@nkbt
Copy link
Author

nkbt commented Feb 10, 2016

if I don't want to use Classes in ruby but want to have just collection of functions (some exposed as public and some for internal use only), am I totally doomed? can't find the way to do it

@nkbt
Copy link
Author

nkbt commented Feb 10, 2016

Ok. I am doomed to use class

module Test
  class << self
    def get
      y x
    end

    private

    def x
      'x'
    end

    def y arg
      arg + 'y'
    end
  end
end


puts Test.get
10:50 $ ruby test.rb 
xy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment