Created
April 2, 2017 23:36
-
-
Save nelldnine/e311842ed1fbc4d78081efcd18a1c2e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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