Class: XASH::Type
- Inherits:
-
Object
- Object
- XASH::Type
- Defined in:
- lib/xash/type.rb
Class Method Summary collapse
- .collection?(collection) ⇒ Boolean
- .executable?(executable) ⇒ Boolean
- .lambda?(lambda) ⇒ Boolean
- .to_collection(collection) ⇒ Object
Class Method Details
.collection?(collection) ⇒ Boolean
21 22 23 |
# File 'lib/xash/type.rb', line 21 def collection?(collection) collection.is_a? String or collection.respond_to? :to_a end |
.executable?(executable) ⇒ Boolean
25 26 27 |
# File 'lib/xash/type.rb', line 25 def executable?(executable) lambda?(executable) or context?(executable) end |
.lambda?(lambda) ⇒ Boolean
17 18 19 |
# File 'lib/xash/type.rb', line 17 def lambda?(lambda) lambda.is_a? Hash and lambda.to_a[0][0] == 'do' end |
.to_collection(collection) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/xash/type.rb', line 29 def to_collection(collection) case collection when String collection.each_char.to_a when ->(c){ c.is_a? Hash and c.key? 'range' } f, e, l = collection['range'] Range.new(f.to_i, l.to_i, e == '...').to_a else raise TypeError, "`#{collection}` is not collection" unless collection? collection collection.to_a end end |