# Comments
not_comment # comment
=begin
comment
=end
=begin
not_comment
=end
# Strings
'string'
"string"
%q(string)
%q[string]
%q{string}
%q<string>
%q|string|
%Q(string)
%Q[string]
%Q{string}
%Q<string>
%Q|string|
foo('string', 'string')
"unsupported\"string"
# Heredocs
if true
DOC = foo(<<-DOC)
heredoc
xxx
xxx
DOC
# ^heredoc ends here
DOC
end
if true
DOC = foo(<<DOC)
heredoc
xxx
xxx
DOC
DOC
# ^heredoc ends here
end
# Symbols
:symbol
:'long symbol'
:"long symbol"
# Regular Expressions
/regex/xxx
%r(regex)xxx
%r[regex]xxx
%r{regex}xxx
%r<regex>xxx
%r|regex|xxx
foo(/regex/xxx, /regex/xxx)
@path.sub(/^#{@root}/, '')
/unsupported\/regex/
# Classes
class Test < Object
attr_accessor :z
end
x = Test.method(1, 2)
x = Test::method(1, 2)
x = Test::CONSTANT
# Methods
def method(x, y)
z = 3
end
def self.method(x, y)
z = 3
end
# Sigils
$stderr.puts 3
@@foo = 3
@foo = 3
# Data Structures
[:value]
['value']
{:key=>'value'}
{:key => 'value'}
{'key' => 'value'}
{key: 'value'}
foo(:key => 'value')
foo(key: 'value')
# Classes, modules, etc.
module Foo
CONSTANT = 'An \'escaped\' string'
class Bar
def self.something
begin
1 + 1
rescue StandardError => e
puts "Whoa buddy!"
end
class << self
def something
1 + 1
end
end
def something
end
end
end
class MyClass < ::Foo::Bar
end
foo(::Foo::Bar.something)