Class: Naming::Meta

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

Overview

Meta is a container of name and value. This is super class of all naming classes.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Meta

Returns a new instance of Meta.

Parameters:

  • value (Object)

    the value



114
115
116
# File 'lib/naming.rb', line 114

def initialize(value)
  @value = value
end

Class Method Details

.nameSymbol

Return the name as symbol. It is just name, doesn’t include module path.

Examples:

Naming::A.name #=> :A

Returns:

  • (Symbol)

    the name



96
97
98
# File 'lib/naming.rb', line 96

def name
  self.to_s.split("::").last.to_sym
end

.name=(name) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Set the name.

Parameters:

  • name (Symbol)

    the name



107
108
109
# File 'lib/naming.rb', line 107

def name=(name)
  @name = name unless @name
end

.others(array) ⇒ Object

Collect objects from the array excluding named objects which have the same name.

Examples:

Naming::A.values([
  Naming.A(1),
  Naming.B(2),
  "abc",
  Naming.A(3),
  123,
  nil
]) #=> [Naming.B(2), "abc", 123, nil]

Parameters:

  • array (Array)

    target of value extraction



85
86
87
# File 'lib/naming.rb', line 85

def others(array)
  array.select{|elt| not(elt.kind_of?(self))}
end

.values(array) ⇒ Object

Extract values which have the same name from the array.

Examples:

Naming::A.values([
  Naming.A(1),
  Naming.B(2),
  "abc",
  Naming.A(3),
  123,
  nil
]) #=> [1, 3]

Parameters:

  • array (Array)

    target of value extraction



66
67
68
# File 'lib/naming.rb', line 66

def values(array)
  array.select{|elt| elt.kind_of?(self)}.map{|elt| elt.value}
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



135
136
137
138
# File 'lib/naming.rb', line 135

def ==(other)
  return false unless other.kind_of?(self.class)
  @value == other.value
end

#hashObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



142
143
144
# File 'lib/naming.rb', line 142

def hash
  @value.hash
end

#nameSymbol

Return the name.

Returns:

  • (Symbol)

    the name



122
123
124
# File 'lib/naming.rb', line 122

def name
  self.class.name
end

#valueObject

Return the value.

Returns:

  • (Object)

    the value



130
131
132
# File 'lib/naming.rb', line 130

def value
  @value
end