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
- .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.
-
#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
60 |
# File 'lib/ae/basic_object.rb', line 60 alias_method :basic_object_method_added, :method_added |
.method_added(name) ⇒ Object
Detect method additions to Kernel and remove them in the BasicObject class.
64 65 66 67 68 69 |
# File 'lib/ae/basic_object.rb', line 64 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.
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.
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.
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.
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.
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.
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 |
#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
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?
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.
8 9 10 |
# File 'lib/ae/core_ext/helpers.rb', line 8 def true? TrueClass === self end |