Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/hash-utils/object.rb
Overview
Object extension.
Constant Summary collapse
- @@__hash_utils_methods_index =
{ }
- @@__hash_utils_object_index =
[ ]
Class Method Summary collapse
Instance Method Summary collapse
- #**(count) ⇒ Object
- #array? ⇒ Boolean
- #boolean? ⇒ Boolean
- #enumerable? ⇒ Boolean
- #false? ⇒ Boolean
- #hash? ⇒ Boolean
- #in?(range) ⇒ Boolean
- #instance_of_any?(*classes) ⇒ Boolean
- #io? ⇒ Boolean
- #kind_of_any?(*classes) ⇒ Boolean (also: #is_a_any?)
- #number? ⇒ Boolean
- #proc? ⇒ Boolean
- #string? ⇒ Boolean
- #symbol? ⇒ Boolean
- #to_b ⇒ Object
- #to_symbol ⇒ Object (also: #to_sym)
- #true? ⇒ Boolean
Class Method Details
.__hash_utils_instance_respond_to?(call) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hash-utils/object.rb', line 44 def self.__hash_utils_instance_respond_to?(call) if not @@__hash_utils_methods_index.has_key? self instance_methods = self.instance_methods if Ruby::Version >= [1, 9] require "set" @@__hash_utils_methods_index[self] = Set::new(instance_methods) if self != Object @@__hash_utils_methods_index[self] -= @@__hash_utils_object_index end else @@__hash_utils_methods_index[self] = { } _col = @@__hash_utils_methods_index[self] instance_methods.each do |i| _col[i] = true end if self != Object @@__hash_utils_object_index.each do |i| _col.delete(i) end end end end @@__hash_utils_methods_index[self].include? call end |
Instance Method Details
#**(count) ⇒ Object
168 169 170 171 172 |
# File 'lib/hash-utils/object.rb', line 168 def **(count) result = [ ] count.times { result << self.dup } return result end |
#array? ⇒ Boolean
287 288 289 |
# File 'lib/hash-utils/object.rb', line 287 def array? self.kind_of? Array end |
#boolean? ⇒ Boolean
274 275 276 |
# File 'lib/hash-utils/object.rb', line 274 def boolean? self.true? or self.false? end |
#enumerable? ⇒ Boolean
313 314 315 |
# File 'lib/hash-utils/object.rb', line 313 def enumerable? self.kind_of? Enumerable end |
#false? ⇒ Boolean
209 210 211 |
# File 'lib/hash-utils/object.rb', line 209 def false? self.kind_of? FalseClass end |
#hash? ⇒ Boolean
300 301 302 |
# File 'lib/hash-utils/object.rb', line 300 def hash? self.kind_of? Hash end |
#in?(range) ⇒ Boolean
141 142 143 |
# File 'lib/hash-utils/object.rb', line 141 def in?(range) range.include? self end |
#instance_of_any?(*classes) ⇒ Boolean
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/hash-utils/object.rb', line 87 def instance_of_any?(*classes) if classes.first.array? classes = classes.first end classes.each do |cls| if self.instance_of? cls return true end end return false end |
#io? ⇒ Boolean
183 184 185 |
# File 'lib/hash-utils/object.rb', line 183 def io? false end |
#kind_of_any?(*classes) ⇒ Boolean Also known as: is_a_any?
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/hash-utils/object.rb', line 113 def kind_of_any?(*classes) if classes.first.array? classes = classes.first end classes.each do |cls| if self.kind_of? cls return true end end return false end |
#number? ⇒ Boolean
261 262 263 |
# File 'lib/hash-utils/object.rb', line 261 def number? self.kind_of? Numeric end |
#proc? ⇒ Boolean
248 249 250 |
# File 'lib/hash-utils/object.rb', line 248 def proc? self.kind_of? Proc end |
#string? ⇒ Boolean
222 223 224 |
# File 'lib/hash-utils/object.rb', line 222 def string? self.kind_of? String end |
#symbol? ⇒ Boolean
235 236 237 |
# File 'lib/hash-utils/object.rb', line 235 def symbol? self.kind_of? Symbol end |
#to_b ⇒ Object
154 155 156 |
# File 'lib/hash-utils/object.rb', line 154 def to_b !!self end |
#to_symbol ⇒ Object Also known as: to_sym
328 329 330 |
# File 'lib/hash-utils/object.rb', line 328 def to_symbol self.to_s.to_sym end |
#true? ⇒ Boolean
196 197 198 |
# File 'lib/hash-utils/object.rb', line 196 def true? self.kind_of? TrueClass end |