Skip to content

Instantly share code, notes, and snippets.

@malev
Created November 26, 2010 19:00
Show Gist options
  • Save malev/717092 to your computer and use it in GitHub Desktop.
Save malev/717092 to your computer and use it in GitHub Desktop.
Include in Ruby
module MyModule
def my_method(variable)
puts "the variable is " + variable.to_s
end
end
class Clase
include MyModule
attr_accessor :value1, :value2
def initialize(value1, value2)
@value1 = value1
@value2 = value2
end
def one_method
puts "hi there!"
end
def my_method(variable)
puts "ahora el codigo estya aqui"
end
end
objeto = Clase.new("one string", "other string")
objeto.one_method
objeto.my_method("from an interface")
# Ejemplo clarísimo de esto:
############################
#La clase Array implementa el módulo Ennumerable.
#Entonces nosotros podemos llamar al método find, o
#first desde un Array, siendo que estos métodos están definidos en el módulo Ennumerable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment