Skip to content

Instantly share code, notes, and snippets.

@rogercampos
Created December 20, 2011 21:46
Show Gist options
  • Save rogercampos/1503438 to your computer and use it in GitHub Desktop.
Save rogercampos/1503438 to your computer and use it in GitHub Desktop.
Playing with modules
module A
def name= a
@name = a + " mi anonim"
end
end
module Version1
def armotize(name)
mixin = Module.new
mixin.module_eval <<-STR
def #{name}=(a)
@#{name} = a + " mi anonim"
end
STR
include mixin
end
end
module Version2
def armotize(name)
mixin = Module.new
mixin.module_eval <<-STR
def #{name}=(a)
@#{name} = a + " mi anonim"
end
STR
self.const_set "Abraca", mixin
include self.const_get("Abraca")
end
end
class Product
attr_reader :name
extend Version2
armotize :name
# include A
def name= value
super(value + " TU MADRE")
end
end
a = Product.new
p Product.included_modules
a.name = "Hola"
puts a.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment