Module: Taipo::Utilities Private

Defined in:
lib/taipo/utilities.rb

Overview

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

Utility methods for Taipo

Since:

  • 1.4.0

Class Method Summary collapse

Class Method Details

.instance_method?(str) ⇒ Boolean

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.

Note:

All this does is check whether the given string begins with a hash symbol.

Check if a string is the name of an instance method

Parameters:

  • str (String)

    the string to check

Returns:

  • (Boolean)

    the result

Since:

  • 1.4.0



20
21
22
# File 'lib/taipo/utilities.rb', line 20

def self.instance_method?(str)
  str[0] == '#'
end

.object_to_type_def(obj) ⇒ String

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.

Note:

This assume that each element returned by Enumerator#each has the same number of components.

Return the type definition for an object

Parameters:

  • obj (Object)

    the object

Returns:

  • (String)

    a type definition of the object

Since:

  • 1.4.0



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/taipo/utilities.rb', line 35

def self.object_to_type_def(obj)
  return obj.class.name unless obj.is_a? Enumerable

  if obj.is_a? Array
    element_types = Hash.new
    obj.each { |o| element_types[self.object_to_type_def(o)] = true }
    if element_types.empty?
      obj.class.name
    else
      obj.class.name + '<' + element_types.keys.join('|') + '>'
    end
  else
    element_types = Array.new
    obj.each.with_index do |element,index_e|
      element.each.with_index do |component,index_c|
        element_types[index_c] = Hash.new if index_e == 0
        c_type = self.object_to_type_def(component)
        element_types[index_c][c_type] = true
      end
    end
    inner = element_types.reduce('') do |memo,e|
      e_type = e.keys.join('|')
      (memo == '') ? e_type : memo + ',' + e_type
    end
    if element_types.empty?
      obj.class.name
    else
      obj.class.name + '<' + inner + '>'
    end
  end
end

.symbol?(str) ⇒ Boolean

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.

Note:

All this does is check whether the given string begins with a colon.

Check if a string is the name of a symbol

Parameters:

  • str (String)

    the string to check

Returns:

  • (Boolean)

    the result

Since:

  • 1.4.0



77
78
79
# File 'lib/taipo/utilities.rb', line 77

def self.symbol?(str)
  str[0] == ':'
end