A Live Developer Journal

I try to regularly revisit the basics of languages that I am currently learning, because you always learn something awesome each pass through. These notes are based on Programming Ruby - The Pragmatic Bookshelf.

I'm just going to capture some of the things I didn't know, or things that I experiment with.

Oh nice, instead of writing an array of words seperated by quotes and commas, we can just use %w{ ant bee cat dog elk } instead. Cool!

If an if statement is just a single expression, you can write it like this:puts "Danger, Will Robinson" if radiation > 3000.

If a while statement is just a single expression, you can write it in a similar fashion, like this: square = square*square while square < 1000.

Regular expressions

A regular expression is simply a way of specifying a pattern of characters to be matched in a string.

Yield


def call_block
  puts "Start of method"
  yield
  yield
  puts "End of method"
end
call_block { puts "In the block" }

OUTPUT:
Start of method
In the block
In the block
End of method

printf


printf("Number: %5.2f, \nString: %S\N", 1.23, "hello")