Class: Clive::Type::Regexp

Inherits:
Object show all
Defined in:
lib/clive/type/definitions.rb

Constant Summary collapse

OPTS =
{
  'x' => ::Regexp::EXTENDED,
  'i' => ::Regexp::IGNORECASE,
  'm' => ::Regexp::MULTILINE
}

Instance Method Summary collapse

Methods inherited from Object

#valid?

Methods inherited from Clive::Type

cast, find_class, match, refute, typecast, #valid?, valid?

Instance Method Details

#typecast(arg) ⇒ Object



159
160
161
162
163
164
165
166
167
# File 'lib/clive/type/definitions.rb', line 159

def typecast(arg)
  parts = arg.split('/')
  parts << '' if parts.size < 3

  _, arg, mods = parts
  mods = mods.split('').map {|a| OPTS[a] }.inject{|a,e| a | e }

  ::Regexp.new arg, mods
end