include their code in other files with the Ruby include statement : include « Statement « Ruby






include their code in other files with the Ruby include statement


#file: mathematics.rb.
module Mathematics
  def Mathematics.add(operand_one, operand_two)

    return operand_one + operand_two
  end
end

file: sentence.rb
module Sentence
  def Sentence.add(word_one, word_two)
    return word_one + "" + word_two
  end
end

file: ModuleTest.rb
include 'mathematics.rb'
include 'sentence.rb'

puts "2 + 3 = " + Mathematics.add(2, 3).to_s

 








Related examples in the same category