Module: CoreEx::Proc

Included in:
Proc
Defined in:
lib/core_ex/proc.rb

Defined Under Namespace

Modules: ClassMethods Classes: ArityError

Instance Method Summary collapse

Instance Method Details

#instance_call(anObject, *args, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/core_ex/proc.rb', line 41

def instance_call ( anObject, *args, &block )
  argc = args.size
  case arity
    when 1 + argc
      call(anObject, *args, &block)
    when argc, -1
      raise ArgumentError, "No block needed" if block
      anObject.instance_eval_with_args(*args, &self)
    else
      if arity < 0 and argc >= arity.abs - 2
        call(anObject, *args, &block)
      else
        raise ArityError
      end
  end
end

#source_fileObject



21
22
23
# File 'lib/core_ex/proc.rb', line 21

def source_file
  to_s[/#<#{self.class}:.*@(.*):\d*>/, 1]
end

#source_lineObject



25
26
27
# File 'lib/core_ex/proc.rb', line 25

def source_line
  to_s[/#<#{self.class}:.*@.*:(\d*)>/, 1].to_i
end

#source_locationObject



29
30
31
# File 'lib/core_ex/proc.rb', line 29

def source_location
  to_s[/#<#{self.class}:.*@(.*:\d*)>/, 1]
end

#to_procObject



37
38
39
# File 'lib/core_ex/proc.rb', line 37

def to_proc
  self
end

#to_yaml_stringObject



33
34
35
# File 'lib/core_ex/proc.rb', line 33

def to_yaml_string
  to_s
end