Skip to content

Commit

Permalink
add retarded mixin examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zacheryph committed Sep 10, 2010
1 parent 78de468 commit 2e9a78e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions groovy/mixins.groovy
@@ -0,0 +1,12 @@
class MyMixin {
void print_me() {
print "See me Print\n"
}
}

@Mixin(MyMixin)
class Donkey {}

donkey = new Donkey()
print donkey.print_me()

30 changes: 30 additions & 0 deletions ruby/mixins.rb
@@ -0,0 +1,30 @@
module MyMixin
def class_name
self.class.to_s
end
end

module Magical
def magic
puts "Magical: #{rand(100)}"
end
end

class ClassOne
include MyMixin
include Magical
end

class ClassTwo
include MyMixin
include Magical
end

c1 = ClassOne.new
puts "c1.class_name:#{c1.class_name}"
c1.magic

c2 = ClassTwo.new
puts "c2.class_name: #{c2.class_name}"
c2.magic

0 comments on commit 2e9a78e

Please sign in to comment.