Class: Symbol
- Defined in:
- lib/quality_extensions/color/rgb.rb,
lib/quality_extensions/symbol/match.rb,
lib/quality_extensions/symbol/constantize.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#=~(regexp) ⇒ Object
Warning: Due to what I think is a bug in Ruby, $1, Regexp.last_match do not yield accurate results when queried after returning from a method call that does a regexp match! If you need access to that data, you’re better off just doing :symbol.to_s =~ /regexp/ yourself.
-
#constantize ⇒ Object
Tries to find a declared constant with the name specified in self.
- #match(regexp) ⇒ Object
- #to_rgb ⇒ Object
Instance Method Details
#=~(regexp) ⇒ Object
Warning: Due to what I think is a bug in Ruby, $1, Regexp.last_match do not yield accurate results when queried after returning from a method call that does a regexp match! If you need access to that data, you’re better off just doing :symbol.to_s =~ /regexp/ yourself. If all you need is a true/false (matches or doesn’t match) result, then you can use this.
:cat =~ /c.t/
27 28 29 |
# File 'lib/quality_extensions/symbol/match.rb', line 27 def =~(regexp) to_s =~ regexp end |
#constantize ⇒ Object
Tries to find a declared constant with the name specified in self.
:Foo.constantize => Foo
Unlike ActiveSupport, we don’t do this check (because Kernel.module “can handle module hierarchy”):
vendor/rails/activesupport/lib/active_support/inflector.rb
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
end
24 25 26 |
# File 'lib/quality_extensions/symbol/constantize.rb', line 24 def constantize Kernel.constant(self) end |
#match(regexp) ⇒ Object
17 18 19 |
# File 'lib/quality_extensions/symbol/match.rb', line 17 def match(regexp) to_s.match(regexp) end |
#to_rgb ⇒ Object
29 30 31 |
# File 'lib/quality_extensions/color/rgb.rb', line 29 def to_rgb self.to_s.to_rgb end |