Class: HashKey

Inherits:
Object show all
Defined in:
ext/enterprise_script_service/mruby/test/t/hash.rb

Overview

Hash ISO Test

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, error: nil, callback: nil) ⇒ HashKey

Returns a new instance of HashKey.



9
10
11
12
13
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 9

def initialize(value, error: nil, callback: nil)
  @value = value
  @error = error
  @callback = callback
end

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



5
6
7
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 5

def callback
  @callback
end

#errorObject

Returns the value of attribute error.



5
6
7
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 5

def error
  @error
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 5

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



15
16
17
18
19
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 15

def ==(other)
  @callback.(:==, self, other) if @callback
  return raise_error(:==) if @error == true || @error == :==
  other.kind_of?(self.class) && @value == other.value
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 21

def eql?(other)
  @callback.(:eql?, self, other) if @callback
  return raise_error(:eql?) if @error == true || @error == :eql?
  other.kind_of?(self.class) && @value.eql?(other.value)
end

#hashObject



27
28
29
30
31
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 27

def hash
  @callback.(:hash, self) if @callback
  return raise_error(:hash) if @error == true || @error == :hash
  @value % 3
end

#raise_error(name) ⇒ Object



38
39
40
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 38

def raise_error(name)
  raise "##{self}: #{name} error"
end

#to_sObject Also known as: inspect



33
34
35
# File 'ext/enterprise_script_service/mruby/test/t/hash.rb', line 33

def to_s
  "#{self.class}[#{@value}]"
end