Module: Kernel

Defined in:
lib/ae/basic_object.rb,
lib/ae/pry.rb,
lib/ae/core_ext/helpers.rb

Overview

Since Ruby is very dynamic, methods added to the ancestors of BlankSlate after BlankSlate is defined will show up in the list of available BlankSlate methods. We handle this by defining a hook in the Object and Kernel classes that will hide any method defined after BlankSlate has been loaded.

Defined Under Namespace

Classes: Pry

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.basic_object_method_addedObject


59
# File 'lib/ae/basic_object.rb', line 59

alias_method :basic_object_method_added, :method_added

.method_added(name) ⇒ Object

Detect method additions to Kernel and remove them in the BasicObject class.


63
64
65
66
67
68
# File 'lib/ae/basic_object.rb', line 63

def method_added(name)
  result = basic_object_method_added(name)
  return result if self != Kernel
  AE::BasicObject.hide(name)
  result
end

Instance Method Details

#case?(value = NoArgument) ⇒ Boolean

Word form of #===. Also can take a block.

Returns:

  • (Boolean)

35
36
37
38
39
40
41
# File 'lib/ae/core_ext/helpers.rb', line 35

def case?(value=NoArgument) #:yield:
  if block_given?
    self === yield
  else
    self === value
  end
end

#eq?(value = NoArgument) ⇒ Boolean

Word form of #==. Also can take a block.

Returns:

  • (Boolean)

26
27
28
29
30
31
32
# File 'lib/ae/core_ext/helpers.rb', line 26

def eq?(value=NoArgument) #:yield:
  if block_given?
    self == yield
  else
    self == value
  end
end

#equate?(x) ⇒ Boolean

Broad equality.

Returns:

  • (Boolean)

53
54
55
# File 'lib/ae/core_ext/helpers.rb', line 53

def equate?(x)
  equal?(x) || eql?(x) || self == x || self === x
end

#false?Boolean

Is literally false.

Returns:

  • (Boolean)

13
14
15
# File 'lib/ae/core_ext/helpers.rb', line 13

def false?
  FalseClass === self
end

#identical?(exp) ⇒ Boolean Also known as: identical_to?

Are identical, eg. object_id's are equal.

Returns:

  • (Boolean)

18
19
20
# File 'lib/ae/core_ext/helpers.rb', line 18

def identical?(exp)
  exp.object_id == object_id
end

#match?(value = NoArgument) ⇒ Boolean

Word form for #=~. Also can take a block.

Returns:

  • (Boolean)

44
45
46
47
48
49
50
# File 'lib/ae/core_ext/helpers.rb', line 44

def match?(value=NoArgument)
  if block_given?
    self =~ yield
  else
    self =~ value
  end
end

#pryPry

Pry allows you to test private and protected methods thru a public-only interface.

Generally one should avoid testing private and protected methods directly, instead relying on tests of public methods to indirectly test them, because private and protected methods are considered implementation details. But sometimes it is necessary to test them directly, or if you wish to achieve *absolute coverage*, say in a mission critical system.

Returns:

  • (Pry)

    pry functor


21
22
23
24
25
# File 'lib/ae/pry.rb', line 21

def pry
  $PRY_TABLE[self] ||= Pry.new do |op, *a, &b|
    __send__(op, *a, &b)
  end
end

#public_send(m, *a, &b) ⇒ Object

Raises:

  • (NoMethodError)

74
75
76
77
# File 'lib/ae/core_ext/helpers.rb', line 74

def public_send(m,*a,&b)
  raise NoMethodError unless respond_to?(m)
  __send__(m,*a,&b)
end

#send?(method, *args, &block) ⇒ Boolean

Can a message be sent to the receiver successfully?

Returns:

  • (Boolean)

58
59
60
61
62
63
64
65
# File 'lib/ae/core_ext/helpers.rb', line 58

def send?(method, *args, &block)
  begin
    __send__(method, *args, &block)
    true
  rescue NoMethodError
    false
  end
end

#true?Boolean

Is literally true.

Returns:

  • (Boolean)

8
9
10
# File 'lib/ae/core_ext/helpers.rb', line 8

def true?
  TrueClass === self
end