Class: Method

Inherits:
Object show all
Defined in:
lib/core/facets/method/curry.rb,
lib/core/facets/method/public.rb,
lib/core/facets/method/memoize.rb,
lib/core/facets/method/partial.rb,
lib/core/facets/method/composition.rb

Defined Under Namespace

Classes: Composition

Instance Method Summary collapse

Instance Method Details

#*(g) ⇒ Object

Method composition.

Author:

  • Mike Burns


80
81
82
# File 'lib/core/facets/method/composition.rb', line 80

def *(g)
  Composition.new(self, g)
end

#^(n) ⇒ Object

Method repetition.

Author:

  • Mike Burns


87
88
89
90
91
92
93
94
# File 'lib/core/facets/method/composition.rb', line 87

def ^(n)
  if n < 2
    self
  else
    #Composition.new(self, self ^ (n-1))
    Composition.new( *([self] * n) )
  end
end

#curry(*args) ⇒ Object

Curry a Method into a new Proc.


6
7
8
# File 'lib/core/facets/method/curry.rb', line 6

def curry(*args)
  to_proc.curry(*args)
end

#memoize(value) ⇒ Object

Memoize a method by defining a singleton override.

NOTE: This method is not a common core extension and is not loaded automatically when using require 'facets'.

Uncommon:

  • require 'facets/method/memoize'


11
12
13
14
# File 'lib/core/facets/method/memoize.rb', line 11

def memoize(value)
  singleton = (class << receiver; self; end)
  singleton.__send__(:define_method, name){ value }
end

#partial(*args) ⇒ Object

Convert a method into a new partial Proc.


6
7
8
# File 'lib/core/facets/method/partial.rb', line 6

def partial(*args)
  to_proc.partial(*args)
end

#private?Boolean

Returns true if self encapsulates a private method.

Returns:

  • (Boolean)

    Returns true if self encapsulates a private method.

Author:

  • Robert Gleeson


29
30
31
# File 'lib/core/facets/method/public.rb', line 29

def private?
  receiver.private_methods.include? name
end

#protected?Boolean

Returns true if self encapsulates a protected method.

Returns:

  • (Boolean)

    Returns true if self encapsulates a protected method.

Author:

  • Robert Gleeson


19
20
21
# File 'lib/core/facets/method/public.rb', line 19

def protected?
  receiver.protected_methods.include? name
end

#public?Boolean

Returns true if self encapsulates a public method.

Returns:

  • (Boolean)

    Returns true if self encapsulates a public method.

Author:

  • Robert Gleeson


9
10
11
# File 'lib/core/facets/method/public.rb', line 9

def public?
  receiver.public_methods.include? name
end