Is this a kind of design patterns?

I got great improvements to make color usage enterprise ready…

Here comes my first class color object using state-of-the-art
design patterns for better scalability and performance

I was designed using the rational design process + UML

class ColorRegistry
private

def self.mix(*colors)
r,g,b=[0,0,0]
while color = colors.shift
r += color[0]
g += color[1]
b += color[2]
end
[r,g,b]
end

RED = [255,0,0]
GREEN = [0,0b11111111,0]
BLUE = [0,0,0xff]
WHITE = mix(RED, GREEN, BLUE)
YELLOW = mix(RED, GREEN)

more to come

public
def self.get_binding
binding
end

end

class ColorEvaluator
def self.get(name)
eval(name.upcase, ColorRegistry.get_binding)
end
end

puts ColorEvaluator.get(“yellow”)
puts ColorEvaluator.get(“red”)
puts ColorEvaluator.get(“white”)

On Mar 23, 2006, at 3:31 PM, Stephen B. wrote:

“This is a fruit: apple.”
The easy answer to your question is to use eval():

fruit = “apple”
=> “apple”

f = ‘This is a fruit: #{fruit}.’
=> “This is a fruit: #{fruit}.”

eval %Q{"#{f}"}
=> “This is a fruit: apple.”

The right answer is to use a template library, like the standard ERB:

f = “This is a fruit: <%= fruit %>.”
=> “This is a fruit: <%= fruit %>.”

require “erb”
=> true

ERB.new(f).result(binding)
=> “This is a fruit: apple.”

Hope that helps.

James Edward G. II

I have a bunch of template documents which I need to manipulate in
very simple ways. I’d like to be able to insert Ruby variables into
the template. Here is a very short example:

file fruit_template.txt: This is a fruit: #{fruit}.

fruit = “apple”
f = IO.read(“fruit_template.txt”)

Then somehow I’d like to end up with this string:
“This is a fruit: apple.”

This works fine of course if I construct the string in Ruby:
s = “This is a fruit: #{fruit}.”
=> “This is a fruit: apple.”

Thanks for any advice.