Skip to content

Instantly share code, notes, and snippets.

@nickethier
Created December 5, 2012 19:21
Show Gist options
  • Save nickethier/4218679 to your computer and use it in GitHub Desktop.
Save nickethier/4218679 to your computer and use it in GitHub Desktop.
wtf ruby
#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