Class: Attribool::Attribute

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

Overview

Abstraction for an attribute to determine its name, reader, writer, and instance variable name.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, reader_name = nil) ⇒ Attribute

Create an Attribute. The attribute can either be a String or a Symbol.

Parameters:

  • attribute (String, Symbol)
  • reader_name (String, Symbol, Proc, nil) (defaults to: nil)


38
39
40
41
42
43
44
45
# File 'lib/attribool/attribute.rb', line 38

def initialize(attribute, reader_name = nil)
  attribute.to_s.then do |a|
    @name = a
    @ivar = "@#{a}"
    @reader = Attribool::ReaderName.new(name, reader_name).to_s
    @writer = "#{name}="
  end
end

Instance Attribute Details

#ivarString (readonly)

The name of the instance variable for the attribute, with the leading “@”.

Returns:

  • (String)


18
19
20
# File 'lib/attribool/attribute.rb', line 18

def ivar
  @ivar
end

#nameString (readonly)

The name of the attribute, without the leading “@”.

Returns:

  • (String)


12
13
14
# File 'lib/attribool/attribute.rb', line 12

def name
  @name
end

#readerString (readonly)

The name of the reader for the attribute.

Returns:

  • (String)


24
25
26
# File 'lib/attribool/attribute.rb', line 24

def reader
  @reader
end

#writerString (readonly)

The name of the writer for the attribute.

Returns:

  • (String)


30
31
32
# File 'lib/attribool/attribute.rb', line 30

def writer
  @writer
end