Created
December 5, 2012 19:21
-
-
Save nickethier/4218679 to your computer and use it in GitHub Desktop.
wtf ruby
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
#Goal is to print \[%{HTTPDATE\] from an array, so the final string will look like: ["\[%{HTTPDATE}\]"] | |
puts "\[%{HTTPDATE}\]" | |
puts '\[%{HTTPDATE}\]' | |
puts "\\[%{HTTPDATE}\\]" | |
puts '\\[%{HTTPDATE}\\]' | |
puts ["\[%{HTTPDATE\]"].inspect | |
puts ["\[%{HTTPDATE\]"].to_s | |
puts ["\\[%{HTTPDATE\\]"].inspect | |
puts ["\\[%{HTTPDATE\\]"].to_s | |
puts ['\[%{HTTPDATE\]'].inspect | |
puts ['\[%{HTTPDATE\]'].to_s | |
puts ['\\[%{HTTPDATE\\]'].inspect | |
puts ['\\[%{HTTPDATE\\]'].to_s | |
#Shave the yak | |
puts "[" + ['\[%{HTTPDATE}\]'].collect{|a| '"' + a.to_s + '"'}.join(",") + "]" | |
#example | |
arr = [ '@source_path', '%{NOTSPACE}tomcat/%{WORD:application}/.*', | |
'@message', '%{NOTSPACE:remote_ip:ip} %{NOTSPACE:clientip:ip} (-|%{NOTSPACE:username}) (-|%{NOTSPACE:user}) \[%{HTTPDATE:timestamp}\] %{NOTSPACE:method} %{NOTSPACE:path} %{NOTSPACE:protocol} %{INT:response_code} (-|%{INT:bytes_sent:int}) h-%{NOTSPACE:hostname} sid- %{NOTSPACE:sid}' | |
] | |
puts "----" | |
puts arr.inspect | |
puts arr.to_s | |
puts "[" + arr.collect{|a| '"' + a.to_s + '"'}.join(",") + "]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment