Skip to content

Instantly share code, notes, and snippets.

@nelldnine
Created April 2, 2017 23:36
Show Gist options
  • Save nelldnine/e311842ed1fbc4d78081efcd18a1c2e5 to your computer and use it in GitHub Desktop.
Save nelldnine/e311842ed1fbc4d78081efcd18a1c2e5 to your computer and use it in GitHub Desktop.
# print prints, puts adds a break line?
puts 'Hello world'
# for loop!
[1, 2, 3].each { |e| puts e }
# classes is over
class Person
def initialize(fname, lname)
@fname = fname
@lname = lname
end
def to_s
"Person: #@fname #@lname"
end
end
person = Person.new('Juan', 'de la Cruz')
puts person
# string interpolation
puts "#{Time.now}"
# read file
file = File.new('hello.rb')
puts file.read
# read first line from file IO
lines = IO.readlines('hello.rb')
puts lines[0]
# print file IO for each
IO.foreach('hello.rb') { |line| puts line }
# convert strings to array, escape with space
STATES = %w(hello world lorem\ ipsum)
puts STATES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment