invoking proc with instance_eval with arguments?

Use instance_exec instead of instance_eval when you need to pass arguments.

proc = Proc.new do |greeting| 
  puts self.hi + greeting
end

class Usa
  def hi
    "Hello, "
  end
end
Usa.new.instance_exec 'world!', &proc # => "Hello, world!"

Note: it’s new to Ruby 1.8.7, so upgrade or require 'backports' if needed.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)