Module: Kernel

Defined in:
lib/assay/ae/core_ext.rb,
lib/assay/core_ext/kernel.rb,
lib/assay/fluidity/assert.rb

Overview

Query methods the AE notation relies on. Most are also in Ruby Facets. Kernel#identical?, #true? and #false? come with Assay itself.

Instance Method Summary collapse

Instance Method Details

#boolean? ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/assay/core_ext/kernel.rb', line 44

def boolean?
  true? || false?
end

#case?(value = NA) ⇒ Boolean

Word form of #===. Can take a block instead of a value.

Returns:

  • (Boolean)


11
12
13
# File 'lib/assay/ae/core_ext.rb', line 11

def case?(value=NA) #:yield:
  self === (block_given? ? yield : value)
end

#eq?(value = NA) ⇒ Boolean

Word form of #==. Can take a block instead of a value.

Returns:

  • (Boolean)


6
7
8
# File 'lib/assay/ae/core_ext.rb', line 6

def eq?(value=NA) #:yield:
  self == (block_given? ? yield : value)
end

#equate?(x) ⇒ Boolean

Broad equality: identical, eql?, == or ===.

Returns:

  • (Boolean)


25
26
27
# File 'lib/assay/ae/core_ext.rb', line 25

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

#false? ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/assay/core_ext/kernel.rb', line 39

def false?
  FalseClass === self
end

#identical?(other) ⇒ Boolean

Do two references have the same #object_id, and hence are the same object.

Parameters:

  • other (Object) —

    Any object reference.

Returns:

  • (Boolean)


9
10
11
# File 'lib/assay/core_ext/kernel.rb', line 9

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

#like?(other) ⇒ Boolean

Ascertain likeness, returns true if any of equal?, eql?, == or === evaluate truthfully, either with self as the receiver or other as the receiver.

Parameters:

  • other (Object) —

    Any object reference.

Returns:

  • (Boolean) —

    true if alike.



22
23
24
25
26
27
28
29
30
31
# File 'lib/assay/core_ext/kernel.rb', line 22

def like?(other)
  self.equal?(other) ||
  self.eql?(other)   ||
  self.==(other)     ||
  self.===(other)    ||
  other.equal?(self) ||
  other.eql?(self)   ||
  other.==(self)     ||
  other.===(self)    ? true : false
end

#match?(value = NA) ⇒ Boolean

Word form of #=~. Can take a block instead of a value. An object without #=~ matches nothing, as Object#=~ did before Ruby 3.2.

String, Symbol and Regexp have their own #match?.

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/assay/ae/core_ext.rb', line 19

def match?(value=NA)
  value = yield if block_given?
  respond_to?(:=~) ? (self =~ value) : nil
end

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

Can a message be sent to the receiver successfully? Only a missing method counts as failure; a NoMethodError raised from inside the method is a bug, and is raised as usual.

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/assay/ae/core_ext.rb', line 32

def send?(method, *args, **kw, &block)
  __send__(method, *args, **kw, &block)
  true
rescue NoMethodError => error
  raise unless error.name == method.to_sym && error.receiver.equal?(self)
  false
end

#true? ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/assay/core_ext/kernel.rb', line 34

def true?
  TrueClass === self
end