Reputation: 91
cat module1.rb :
#!/home/user1/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
Module module1
def add(a,b)
return a+b
end
def subtract(a,b)
return a-b
end
end
temp = "nothing"
temp.extend module1
temp.add(5,2)
ruby module1.rb =>
module1.rb:13: syntax error, unexpected keyword_end, expecting $end
Can anyone fix it?
Upvotes: 0
Views: 4005
Reputation: 12225
module
keyword is case-sensitive, and, as Ray said, module must be a constant (constant name in Ruby starts with uppercase letter). This works:
module Module1
def add(a,b)
return a+b
end
def subtract(a,b)
return a-b
end
end
temp = "nothing"
temp.extend Module1
temp.add(5,2)
Upvotes: 11
Reputation: 88378
You need a lowercase m to start it all off.
Oh and the module name should be a constant....
Start with
module Module1
Upvotes: 1