At about the 19:00 mark in his RailsConf presentation, David Heinemeier Hansson talks about the downsides of instance_eval
:
For a long time I ranted and raved against
instance_eval
, which is the concept of not using a yielded parameter (likedo |people|
) and just straightdo something
and then evaluate what's in that block within the scope of where you came from (I don't even know if that's a coherent explanation)For a long time I didn't like that because it felt more complex in some sense. If you wanted to put your own code in there were you going to trigger something that was already there? Were you going to override something? When you're yielding a specific variable you can chain everything off that and you can know [you're] not messing with anybody else's stuff
This sounded interesting, but a) I don't know how how instance_eval
works in the first place and b) I don't understand why it can be bad / increase complexity.
Can someone explain?