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
Class Method Summary collapse
-
.instance_method?(str) ⇒ Boolean
private
Check if a string is the name of an instance method.
-
.object_to_type_def(obj) ⇒ String
private
Return the type definition for an object.
-
.symbol?(str) ⇒ Boolean
private
Check if a string is the name of a symbol.
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.
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
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.
This assume that each element returned by Enumerator#each has the same number of components.
Return the type definition for an object
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.
All this does is check whether the given string begins with a colon.
Check if a string is the name of a symbol
77 78 79 |
# File 'lib/taipo/utilities.rb', line 77 def self.symbol?(str) str[0] == ':' end |