Skip to content

mrattle/ruby-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

RUBY CHEATSHEET

RULE #1 - WE DON'T TALK ABOUT i++

RULE #2 - WE DON'T TALK ABOUT i++

CASTING METHODS

  • .to_i - Casts to int by dropping anything after decimal point from a float, no rounding
  • .to_f - Casts to float
  • .to_s - Casts to string
  • .to_sym - Casts to symbol

STRING CONCATENATION && SUBSTRINGS

  • Use +, << or .concat() to concatenate strings
  • "hello"[0..1] # => "he"
  • "hello"[0, 4] # => "hell"
  • "hello"[-1] # => "o"`

ESCAPE CHARACTERS

\\ #=> backslash
\b #=> backspace
\r #=> carriage return
\n #=> newline
\s #=> space
\t #=> tab
\" #=> double quotation
\' #=> single quotation

STRING INTERPOLATION - STRING PLACEHOLDERS FOR VARIABLES

name = "Mark"
puts "Oh, hi #{name}!" #=> "Oh, hi Mark!"
puts 'Oh, hi #{name}!' #=> "Oh, hi #{name}!"
  • Must use double quotation marks for string interpolation to work!

About

Ruby Cheatsheet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published