Skip to content

Instantly share code, notes, and snippets.

@lnznt
lnznt / percent_W.rb
Created May 1, 2012 04:44
[sample] the % notation [ %W!...! ] (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
x = "xyz"
@lnznt
lnznt / percent_r.rb
Created May 1, 2012 04:49
[sample] the % notation [ %r!...! ] (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
x = "xyz"
@lnznt
lnznt / percent_x.rb
Created May 1, 2012 04:54
[sample] the % notation [ %x!... ! ] (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
x = "xyz"
@lnznt
lnznt / numeric.rb
Created May 1, 2012 07:00
[sample] numeric (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
p 10 #=> 10
p 1_000 #=> 1000
@lnznt
lnznt / sample_here_document.rb
Created May 1, 2012 07:21
[sample] here document (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
x = "world"
p <<S #=> "hello, world\n"
hello, #{x}
S
p <<'!' #=> "hello, #{x}\n"
@lnznt
lnznt / sample-unicode_escape.rb
Created May 7, 2012 14:20
[sample] Unicode Escape (Ruby)
# coding: UTF-8
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
puts "%#x" % "あ".ord #=> 0x3042
p "あ" == "\u3042" #=> true
p "\u3042" #=> "あ"
@lnznt
lnznt / sample-backslash_escape.rb
Created May 7, 2012 15:18
[sample] Backslash Escape (Ruby)
# coding: UTF-8
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
#
# "\C-x" ..... control character
# "\M-x" ..... meta character
@lnznt
lnznt / sample-builtin_variable.rb
Created May 10, 2012 11:56
[sample] symbols, built in variables (Ruby)
#
# $ ruby -v
# ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
#
p $! # OK
p $" # OK
#p $# ### Syntax Error
p $$ # OK
#p $% ### Syntax Error
@lnznt
lnznt / rcat.rb
Last active October 4, 2015 15:28
[sample] syntax highlight -- use library Ripper (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
=begin
usage: $ ruby rcat.rb ruby-script.rb
=end
require 'ripper'
@lnznt
lnznt / sample-escape_sequence.rb
Created May 12, 2012 01:10
[sample] terminal escape sequence (Ruby)
#!/usr/bin/env ruby
# -*- coding: UTF-8 -*-
puts "\e[0m" "escape sequence(0m)" "\e[m" # RESET or NORMAL
puts "\e[1m" "escape sequence(1m)" "\e[m" # BRIGHT or BOLD
puts "\e[2m" "escape sequence(2m)" "\e[m"
puts "\e[3m" "escape sequence(3m)" "\e[m"
puts "\e[4m" "escape sequence(4m)" "\e[m" # UNDERLINE
puts "\e[5m" "escape sequence(5m)" "\e[m"
puts "\e[6m" "escape sequence(6m)" "\e[m"