Created
September 8, 2010 11:09
-
-
Save yitsushi/569971 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File: person_module.rb | |
module Person | |
def age | |
Time.now - self.birthday | |
end | |
end | |
# File: main.rb | |
require 'person_module' | |
class Man | |
include Person | |
end | |
# Then the Man class have a function: age | |
########## Othe example | |
# File: functions.rb | |
module Functions | |
def operation_a(a) | |
a * 2 | |
end | |
def operation_b(b) | |
b * 10 | |
end | |
end | |
# File: main.rb | |
require 'functions' | |
# call operations | |
puts Functions.operation_a( 10 ) | |
puts Functions.operation_a( 4 ) | |
# But if i include the module | |
include Functions | |
puts operation_a( 10 ) | |
puts operation_a( 4 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment