Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/constructor_core/string.rb

Instance Method Summary collapse

Instance Method Details

#accusativeObject



23
24
25
# File 'lib/constructor_core/string.rb', line 23

def accusative
  self.sub(/(.*)ая( ?)/, '\1ую\2').sub(/(.*)а( (.+))?$/, '\1у\2').sub(/(.*)я( (.+))?$/, '\1ю\2')
end

#boolean?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'lib/constructor_core/string.rb', line 9

def boolean?
  if self =~ (/(true|yes)$/i) || self =~ (/(false|no)$/i)
    return true
  else
    return false
  end
end

#numeric?Boolean

Returns:

  • (Boolean)


4
5
6
7
# File 'lib/constructor_core/string.rb', line 4

def numeric?
  return true if self =~ /^\d+$/
  true if Float(self) rescue false
end

#to_booleanObject

Raises:

  • (ArgumentError)


17
18
19
20
21
# File 'lib/constructor_core/string.rb', line 17

def to_boolean
  return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
  return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
  raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end