Alexandre
Alexandre

Reputation: 13308

Block doesn't work with `{ }`

This one is working

[:dev1, :dev2, :dev3].each do |env|
  define_method "#{env.to_s}?" do  
    settings.environment == env
  end
end

but this is not

[:dev1, :dev2, :dev3].each do |env|
  define_method "#{env.to_s}?" { settings.environment == env }
end

it causes the error because of using { ... } syntax. why?

Upvotes: 0

Views: 94

Answers (1)

Gosha A
Gosha A

Reputation: 4570

It is probably because the method takes other arguments besides a block, and you're omitting parentheses.

Try it this way:

define_method("#{env.to_s}?") { settings.environment == env }

Upvotes: 8

Related Questions