Sha256: 89de2bfd7adb319118ab49743b2efed44e8f48451d9814186a040fca70eedf66

Contents?: true

Size: 776 Bytes

Versions: 1

Compression:

Stored size: 776 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 self.coerce(arg, default = nil)
        return default unless arg
        arg.collect {|member| @subtype.coerce(member) }
      end

      def self.[] (subtype)
        @subtype = subtype
        self
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
attribrutal-0.0.10 lib/attribrutal/coercion.rb