Class: MoulinRouge::CanCan::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/moulin_rouge/cancan/method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *args, &block) ⇒ Method

Returns a new instance of Method.



5
6
7
# File 'lib/moulin_rouge/cancan/method.rb', line 5

def initialize(name, *args, &block)
  @name, @args, @block = name, args, block
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/moulin_rouge/cancan/method.rb', line 4

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/moulin_rouge/cancan/method.rb', line 4

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/moulin_rouge/cancan/method.rb', line 4

def name
  @name
end

Instance Method Details

#send_to(object, proc_scope = nil) ⇒ Object

Send this method to the given object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/moulin_rouge/cancan/method.rb', line 10

def send_to(object, proc_scope = nil)
  # Evaluate any proc in args
  if args.last.is_a?(Hash)
    args.last.each do |key, value|
      if value.is_a?(Proc)
        args.last[key] = value.call(proc_scope || object)
      end
    end
  end
  # Send
  object.send(name, *args, &block)
end