Class: Naming::Meta

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

Overview

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

Class Method Summary collapse

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



50
51
52
# File 'lib/naming/meta.rb', line 50

def name
  self.to_s.split("::").last.to_sym
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



39
40
41
# File 'lib/naming/meta.rb', line 39

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



20
21
22
# File 'lib/naming/meta.rb', line 20

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