3. Example
d::Base
< A ctiveRecor
class User e}")
def tweet _name My nam e is #{nam
.se nd_tweet("
TwitterLib
end
end
user = User.find(42)
user.tweet_name
4. Example
cor d::Base
< ActiveRe
class User
end
module TwitterUser
def tweet_name
TwitterLib.send_tweet("M
y name is #{name}")
end
end
user = User.find(42)
user.extend(TwitterUser)
user.tweet_name
6. Performance ?
Benchmark.ips do |bm|
bm.report("without dci") { ExampleClass.new.foo }
bm.report("with dci") do
obj = ExampleClass.new
obj.extend(ExampleMixin)
obj.foo
end
end
Local - Ok
Global - What ?!
7. Ruby’s cache
Ruby VMs cache methods
« These caches remain valid so long
as we don’t see new types and the
class hierarchy doesn’t change. »
Tony Arceria
8. Alternative
cor d::Base
< ActiveRe
class User
Evan Light
end
class TwitterUser < Simp
leDelegator
def tweet_name
TwitterLib.send_tweet("M
y name is #{name}")
end
end
user = User.find(42)
tw_user = TwitterUser.new(user)
tw_user.tweet_name