0

Let's say you have such method:

def log_yield(sql, args=nil)
  sql = "#{sql}; #{args.inspect}" if args
  t0 = Time.now
  begin
    yield
  rescue => e
    log_exception(e, sql)
    raise
  ensure
    t1 = Time.now
    log_duration(Integer((t1-t0)*1000), sql) unless e
  end
end

I need to override this method and implement it in similar manner BUT I need to get the block that gets returned by yield.

(specifically, I need to identify what block generated particular sql in Sequel::Database)

LetMeSOThat4U
  • 6,470
  • 10
  • 53
  • 93

1 Answers1

0

Blocks are just glorified parameters. In the method its added for you by the ruby implementation but in general you can define your method as:

def log_yield(sql, args=nil, &block)
    # do whatever you want with the block here
end

Of course you are free to override it as you wish in an inherited class. If the block is not provided there you can alter your logic in the method as well using block_given?.

enticedwanderer
  • 4,346
  • 28
  • 24