-
-
Save gene1wood/a70fa860cfa2a527879b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby -v | |
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux] | |
$ ruby symbol_literals.rb | |
valid as first char: | |
@$_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz | |
valid as middle char: | |
_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 | |
valid as end char: | |
!_=?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 | |
valid as a single character | |
(eval):1: warning: invalid character syntax; use ?\s | |
`~!%^&*-_+|<>/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz | |
$ # Note the eval warning relates to the disallowed symbol of :? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def symbol_chars_are_valid(symbol_chars) | |
# :aaa == :"aaa" if it has valid Symbol literal chars | |
# puts "trying #{symbol_chars}" | |
x = eval ":#{symbol_chars} == :#{symbol_chars.inspect}" | |
rescue Exception | |
false | |
end | |
chars_to_try = | |
'`~!@$%^&*()-_+={}[]|\;:"<>,.?/'.split('') + ["'"] + | |
('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a | |
puts "valid as first char:" | |
puts chars_to_try.select {|c| symbol_chars_are_valid "#{c}aa" }.join '' | |
puts "valid as middle char:" | |
puts chars_to_try.select {|c| symbol_chars_are_valid "a#{c}a" }.join '' | |
puts "valid as end char:" | |
puts chars_to_try.select {|c| symbol_chars_are_valid "aa#{c}" }.join '' | |
puts "valid as a single character symbol" | |
puts chars_to_try.select {|c| symbol_chars_are_valid "#{c}" }.join '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment