class Cl::Cast::Cast
Constants
- FALSE
- TRUE
Public Instance Methods
apply()
click to toggle source
# File lib/cl/cast.rb, line 7 def apply return send(type) if respond_to?(type, true) raise ArgumentError, "Unknown type: #{type}" rescue ::ArgumentError => e raise ArgumentError.new(:wrong_type, value.inspect, type) end
Private Instance Methods
array()
click to toggle source
# File lib/cl/cast.rb, line 16 def array Array(value).compact.flatten.map { |value| split(value) }.flatten.compact end
boolean()
click to toggle source
# File lib/cl/cast.rb, line 25 def boolean return true if value.to_s =~ TRUE return false if value.to_s =~ FALSE !!value end
float()
click to toggle source
# File lib/cl/cast.rb, line 38 def float Float(value) if value end
int()
click to toggle source
# File lib/cl/cast.rb, line 33 def int Integer(value) if value end
Also aliased as: integer
separator()
click to toggle source
# File lib/cl/cast.rb, line 46 def separator opts[:separator] end
split(value)
click to toggle source
# File lib/cl/cast.rb, line 42 def split(value) separator ? value.to_s.split(separator) : value end
string()
click to toggle source
# File lib/cl/cast.rb, line 20 def string value.to_s unless value.to_s.empty? end
Also aliased as: str