Class: Method

Inherits:
Object show all
Defined in:
lib/more/facets/curry.rb,
lib/more/facets/advice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#advice_afterObject

Returns the value of attribute advice_after.



37
38
39
# File 'lib/more/facets/advice.rb', line 37

def advice_after
  @advice_after
end

#advice_aroundObject

Returns the value of attribute advice_around.



38
39
40
# File 'lib/more/facets/advice.rb', line 38

def advice_around
  @advice_around
end

#advice_beforeObject

Returns the value of attribute advice_before.



36
37
38
# File 'lib/more/facets/advice.rb', line 36

def advice_before
  @advice_before
end

#advisedObject

Returns the value of attribute advised.



34
35
36
# File 'lib/more/facets/advice.rb', line 34

def advised
  @advised
end

Instance Method Details

#advised?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/more/facets/advice.rb', line 40

def advised?
  @advised
end

#call_with_advice(obj, *args, &blk) ⇒ Object

Call with advice.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/more/facets/advice.rb', line 50

def call_with_advice(obj, *args, &blk)
  advice_before.each do |name|
    #advice.call(*args, &blk)
    obj.send(name, *args, &blk)
  end

  target = lambda{ call(*args, &blk) }
  advice_around.each do |name|
    target = lambda_target(obj, name, target, *args, &blk)
  end
  ret = target.call

  advice_after.reverse_each do |name|
    #advice.call(*args, &blk)
    obj.send(name, *args, &blk)
  end

  return ret
end

#curry(*args) ⇒ Object

Curry a Method into a new Proc.



58
59
60
61
62
63
64
65
# File 'lib/more/facets/curry.rb', line 58

def curry(*args)
  Proc.new do |*spice|
    result = args.collect do |a|
      MissingArgument == a ? spice.pop : a
    end
    call(*result)
  end
end