Hey there,

Lets have a look at nice ruby styles:

One line if

something=true
puts "Hello" if something==true # => Hello
puts "Hello" if something # => Hello

One line unless

something=true
puts "Hello" unless something==true # => nil
puts "Hello" unless something # => nil

One line if else (Ternary Operator)

something=true
puts something ? "something is true" : "something is NOT true" # => something is true

Beautiful when

something=true
case something
  when true then puts "something is true"
  when false then puts "something is false"
else puts "something is neither true nor false"
end

# => something is true

Conditional Assignment

foo="Hello"
#Notice that bar does not exist
foo ||= "Goodbye"
bar ||= "Goodbye"
puts foo # => "Hello"
puts bar # => "Goodbye"

# ||= assigns ONLY IF variable is nil

Implicit Return

def foo
  return "Hello"
end

# is the same as:

def foo
  "Hello"
end

# You dont need to implicit return
# The last evaluated line returns anyway

Using the shovel

# Thats the shovel: <<
array=[1,2,3]
array<<4
p array # => [1, 2, 3, 4]

string="Hello"
string<<"World"
p string # => "HelloWorld"

# as you can see it shovels realy well no matter what

#String interpolation

count=99
puts "I have " + counter.to_s + " problems but an integer ain't one"
puts "I have " << counter.to_s << " problems but an integer ain't one"

# If you want to concatenate strings and integers you need to use .to_s
# in order to convert the integers to strings.
# Lets do it the ruby way with interpolation:

puts "I have #{counter} problems but an integer ain't one"