Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created September 8, 2010 11:09
Show Gist options
  • Save yitsushi/569971 to your computer and use it in GitHub Desktop.
Save yitsushi/569971 to your computer and use it in GitHub Desktop.
# 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