Skip to content

Instantly share code, notes, and snippets.

@brenes
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save brenes/c556ed0d0070e27444b5 to your computer and use it in GitHub Desktop.

Select an option

Save brenes/c556ed0d0070e27444b5 to your computer and use it in GitHub Desktop.
extending objects through modules
class A
def to_s
"a"
end
end
module B
def to_s
super + "b"
end
end
a = A.new
puts a.to_s # => a
b = A.new
puts b.to_s # => a
b.extend B
puts a.to_s # => a
puts b.to_s # => ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment