module Etter
Top level namespace for Etter
. Behaves somewhat like a class, in that you can send ::new
to it, but will not return anything other than a String
or Sumbol
Constants
- ERROR
- VERSION
Public Class Methods
getter(obj)
click to toggle source
# File lib/etter/etter.rb, line 22 def getter(obj) _validate_internal obj obj.intern end
new(string) → string
click to toggle source
new(symbol) → symbol
# File lib/etter/etter.rb, line 13 def new(obj) attribute = _attrify(obj) if obj.is_a? Symbol return attribute.intern else return attribute end end
setter(obj)
click to toggle source
# File lib/etter/etter.rb, line 27 def setter(obj) _validate_internal obj (obj.to_s + "=").intern end
Private Class Methods
_attrify(obj)
click to toggle source
# File lib/etter/etter.rb, line 33 def _attrify(obj) _validate_internal(obj) obj = literal2snk(obj) if obj[0] == '@' return obj else return obj.prepend '@' end end
_validate_internal(obj)
click to toggle source
# File lib/etter/etter.rb, line 48 def _validate_internal(obj) raise NameError, "`#{obj}' #{ERROR}" unless obj.is_a?(String) || obj.is_a?(Symbol) raise NameError, "`#{obj}' #{ERROR}" unless obj[0] =~ /[a-zA-Z@]/ raise NameError, "`#{obj}' #{ERROR}" unless obj.to_s[1..-1].scan(/[^a-zA-Z0-9-]/).empty? end
extended(mod)
click to toggle source
# File lib/etter/etter.rb, line 57 def self.extended(mod) raise "cannot extend this module. " end
literal2snk(obj)
click to toggle source
# File lib/etter/etter.rb, line 43 def literal2snk(obj) rep = obj.to_s.gsub('-', '_') rep end