examples/general/SRL/lib/regex/char_shorthand.rb in rley-0.6.00 vs examples/general/SRL/lib/regex/char_shorthand.rb in rley-0.6.01

- old
+ new

@@ -1,11 +1,10 @@ # File: char_shorthand.rb -require_relative "atomic_expression" # Access the superclass +require_relative 'atomic_expression' # Access the superclass module Regex # This module is used as a namespace - # A pre-defined character class is in essence a name for a built-in, standard character class. class CharShorthand < AtomicExpression # A constant Hash that defines all the predefined character shorthands. # It contains pairs of the form: # a pre-defined character shorthand letter => a CharRange object @@ -16,36 +15,36 @@ 'H' => '[^0-9a-fA-F]', 's' => '[ \t\r\n\f]', 'S' => '[^ \t\r\n\f]', 'w' => '[0-9a-zA-Z_]', 'W' => '[^0-9a-zA-Z_]' - } + }.freeze # An one-letter abbreviation attr_reader(:shortname) # Constructor def initialize(aShortname) @shortname = valid_shortname(aShortname) end protected - + # Conversion method re-definition. # Purpose: Return the String representation of the expression. def text_repr() return "\\#{shortname}" end - private + private + # Return the validated short name. def valid_shortname(aShortname) - raise StandardError, "Unknown predefined character class \\#{aShortname}" unless StandardCClasses.include? aShortname + msg = "Unknown predefined character class \\#{aShortname}" + raise StandardError, msg unless StandardCClasses.include? aShortname return aShortname end - end # class - end # module -# End of file \ No newline at end of file +# End of file