Sha256: b0153be2d30c53a472fca6a2de6145e97817194a361133af5b578c2a4bda50ba
Contents?: true
Size: 821 Bytes
Versions: 1
Compression:
Stored size: 821 Bytes
Contents
module Attribrutal module Type class Boolean def self.coerce(arg, default = nil) if arg == true true else false end end end class Integer def self.coerce(arg, default = nil) if arg.nil? default else Integer(arg) end end end class String def self.coerce(arg, default = nil) if arg.nil? default else String(arg) end end end class Array def initialize(subtype) @subtype = subtype end def coerce(arg, default = nil) return default unless arg arg.collect {|member| @subtype.coerce(member) } end def self.[] (subtype) new(subtype) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
attribrutal-0.0.12 | lib/attribrutal/coercion.rb |