On 15.08.2010 14:28, Andrew Wagner wrote:

> Here's one approach:
>
> def get(name,value)
>    url_method_name = "create_#{name}".to_sym
>    method = # look up create_xxx method, I can't recall the syntax for this
>    method.call(value)
> end

I'd rather use a Hash and lambdas for that since it is more explicit and 
more efficient:

# Note, this is just unsafe dummy URL creation functionality

CREATORS = {
   "foo" => lambda {|val| "http:/foo/#{val}"},
   "bar" => lambda {|val| "http:/google.com/q=#{val}"},
}

def get(name, value)
   CREATORS.fetch name do |key|
     raise ArgumentError, "Cannot find %p" % key
   end.call value
end

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/