Friday, July 28, 2006

Ruby decorator pattern

Is any kind of ruby decorator pattern out-of-the-box there?
so far i didn't find any pure decorator pattern in ruby, instead of this all i have found is the ruby-way of decorating.

(Updated June 2006)
So.. times goes by ... and I found this implementation by Jason Arhart using module.

class Foo
def initialize(s)
@s = s
end
def to_s
@s
end
end

module SingleQuoted
def to_s
"'" + super + "'"
end
end

module DoubleQuoted
def to_s
'"' + super + '"'
end
end

foo = Foo.new('foo')
puts "#{foo.id} - #{foo}"
foo.extend(SingleQuoted)
puts "#{foo.id} - #{foo}"
foo.extend(DoubleQuoted)
puts "#{foo.id} - #{foo}"

2 comments:

michelnelson26356570 said...

Get any Desired College Degree, In less then 2 weeks.

Call this number now 24 hours a day 7 days a week (413) 208-3069

Get these Degrees NOW!!!

"BA", "BSc", "MA", "MSc", "MBA", "PHD",

Get everything within 2 weeks.
100% verifiable, this is a real deal

Act now you owe it to your future.

(413) 208-3069 call now 24 hours a day, 7 days a week.

Anonymous said...

Really amazing! Useful information. All the best.
»