Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module TestFunctions
- def abc
- puts 123
- end
- end
- >> TestFunctions.instance_methods
- => ["abc"]
- >> TestFunctions.abc
- NoMethodError: undefined method `abc' for TestFunctions:Module from (irb):3
- >> TestFunctions::abc
- NoMethodError: undefined method `abc' for TestFunctions:Module from (irb):4
- defined?(TestFunctions::abc) #=> nil, but
- TestFunctions.method_defined? :abc #=> true
- module Foo
- def self.method_one
- end
- def Foo.method_two
- end
- class << self
- def method_three
- end
- end
- end
- module Foo
- def self.method_one
- end
- def Foo.method_two
- end
- class << self
- def method_three
- end
- end
- def method_four
- end
- module_function :method_four
- end
- module TestFunctions
- def abc
- puts 123
- end
- module_function :abc
- end
- TestFunctions.abc # => 123
- module Utilities
- def compute_hello(input_string)
- return "Hello #{input_string}"
- end
- end
- require "test_helper"
- require "utilities"
- class MyTest < ActiveSupport::TestCase
- include Utilities
- def test_compute_hello
- x = compute_hello(input_string="Miles")
- print x
- assert x=="Hello Miles", "Incorrect Response"
- end
- end
- >> class MyTest
- >> include TestFunctions
- >> end
- => MyTest
- >> MyTest.new.abc
- 123
- => nil
- module TestFunctions
- def TestFunctions.abc
- puts 123
- end
- end
- require 'test_functions'
- TestFunctions.abc
- module TestFunctions
- def abc
- puts 123
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement