Module: Kernel
- Defined in:
- lib/ae/basic_object.rb,
lib/ae/pry.rb,
lib/ae/core_ext.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
- .basic_object_method_added ⇒ Object
-
.method_added(name) ⇒ Object
Detect method additions to Kernel and remove them in the BasicObject class.
Instance Method Summary collapse
-
#case?(value = NoArgument) ⇒ Boolean
Word form of #===.
-
#eq?(value = NoArgument) ⇒ Boolean
Word form of #==.
-
#equate?(x) ⇒ Boolean
Broad equality.
-
#false? ⇒ Boolean
Is literally false.
-
#flunk(reason = nil, backtrace = nil) ⇒ Object
Force an Assertion failure.
-
#identical?(exp) ⇒ Boolean
(also: #identical_to?)
Are identical, eg.
-
#match?(value = NoArgument) ⇒ Boolean
Word form for #=~.
-
#pry ⇒ Object
Pry allows you to test private and protected methods, via a public-only interface.
- #public_send(m, *a, &b) ⇒ Object
-
#send?(method, *args, &block) ⇒ Boolean
Can a message be sent to the receiver successfully?.
-
#true? ⇒ Boolean
Is literally true.
Class Method Details
.basic_object_method_added ⇒ Object
64 |
# File 'lib/ae/basic_object.rb', line 64 alias_method :basic_object_method_added, :method_added |
.method_added(name) ⇒ Object
Detect method additions to Kernel and remove them in the BasicObject class.
68 69 70 71 72 73 |
# File 'lib/ae/basic_object.rb', line 68 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.
44 45 46 47 48 49 50 |
# File 'lib/ae/core_ext.rb', line 44 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.
35 36 37 38 39 40 41 |
# File 'lib/ae/core_ext.rb', line 35 def eq?(value=NoArgument) #:yield: if block_given? self == yield else self == value end end |
#equate?(x) ⇒ Boolean
Broad equality.
62 63 64 |
# File 'lib/ae/core_ext.rb', line 62 def equate?(x) equal?(x) || eql?(x) || self == x || self === x end |
#false? ⇒ Boolean
Is literally false.
22 23 24 |
# File 'lib/ae/core_ext.rb', line 22 def false? FalseClass === self end |
#flunk(reason = nil, backtrace = nil) ⇒ Object
Force an Assertion failure.
TODO: Can we call this #fail (overriding built-in)?
12 13 14 |
# File 'lib/ae/core_ext.rb', line 12 def flunk(reason=nil, backtrace=nil) raise Assertion.new((reason || 'flunk'), :backtrace=>(backtrace || caller)) end |
#identical?(exp) ⇒ Boolean Also known as: identical_to?
Are identical, eg. object_id’s are equal.
27 28 29 |
# File 'lib/ae/core_ext.rb', line 27 def identical?(exp) exp.object_id == object_id end |
#match?(value = NoArgument) ⇒ Boolean
Word form for #=~. Also can take a block.
53 54 55 56 57 58 59 |
# File 'lib/ae/core_ext.rb', line 53 def match?(value=NoArgument) if block_given? self =~ yield else self =~ value end end |
#pry ⇒ Object
Pry allows you to test private and protected methods, via a public-only interface.
Generally one should avoid testing private and protected method directly, instead relying on tests of public methods to indirectly test them, because private and protected methods are considered implementation details. But sometimes is necessary to test them directly, or if you wish to achieve *absolute coverage*, say in mission critical systems.
17 18 19 20 21 |
# File 'lib/ae/pry.rb', line 17 def pry $PRY_TABLE[self] ||= Pry.new do |op, *a, &b| __send__(op, *a, &b) end end |
#public_send(m, *a, &b) ⇒ Object
83 84 85 86 |
# File 'lib/ae/core_ext.rb', line 83 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?
67 68 69 70 71 72 73 74 |
# File 'lib/ae/core_ext.rb', line 67 def send?(method, *args, &block) begin __send__(method, *args, &block) true rescue NoMethodError false end end |
#true? ⇒ Boolean
Is literally true.
17 18 19 |
# File 'lib/ae/core_ext.rb', line 17 def true? TrueClass === self end |