class Bake::Types::Any
An ordered list of types. The first type to match the input is used.
```ruby type = Bake::Types::Any(Bake::Types::String, Bake::Types::Integer) ```
Public Class Methods
new(types)
click to toggle source
Initialize the instance with an array of types. @parameter types [Array] the array of types.
# File lib/bake/types/any.rb, line 34 def initialize(types) @types = types end
parse(value)
click to toggle source
As a class type, accepts any value.
# File lib/bake/types/any.rb, line 61 def self.parse(value) value end
Public Instance Methods
composite?()
click to toggle source
Whether any of the listed types is a composite type. @returns [Boolean] true if any of the listed types is `composite?`.
# File lib/bake/types/any.rb, line 46 def composite? @types.any?{|type| type.composite?} end
parse(input)
click to toggle source
Parse an input string, trying the listed types in order, returning the first one which doesn't raise an exception. @parameter input [String] the input to parse, e.g. `“5”`.
# File lib/bake/types/any.rb, line 52 def parse(input) @types.each do |type| return type.parse(input) rescue # Ignore. end end
to_s()
click to toggle source
Generate a readable string representation of the listed types.
# File lib/bake/types/any.rb, line 66 def to_s "any of #{@types.join(', ')}" end
|(other)
click to toggle source
Create a copy of the current instance with the other type appended. @parameter other [Type] the type instance to append.
# File lib/bake/types/any.rb, line 40 def | other self.class.new([*@types, other]) end