Class: Attribool::ReaderName

Inherits:
Object
  • Object
show all
Defined in:
lib/attribool/reader_name.rb

Overview

Abstraction of a reader’s method name.

Instance Method Summary collapse

Constructor Details

#initialize(attribute, name) ⇒ ReaderName

Instantiate new instance of ReaderName.

Parameters:

  • attribute (String, Syumbol)
  • name (proc, nil, String, Symbol)


13
14
15
16
# File 'lib/attribool/reader_name.rb', line 13

def initialize(attribute, name)
  @attribute = attribute
  @name = name
end

Instance Method Details

#to_sString

Convert instance to a string.

Returns:

  • (String)


22
23
24
25
26
27
28
# File 'lib/attribool/reader_name.rb', line 22

def to_s
  case @name
  when Proc then @name.call(@attribute)
  when nil then "#{@attribute}?"
  else @name.to_s
  end
end