Skip to content

Instantly share code, notes, and snippets.

View FerPerales's full-sized avatar
🎯
Focusing

Fernando Perales FerPerales

🎯
Focusing
View GitHub Profile
@FerPerales
FerPerales / gist:3882984
Created October 13, 2012 02:38
Single vs Double
print 'Enter your name: ' #Fer
name = gets()
puts "Hello #{name}" #prints "Hello Fer"
puts 'Hello #{name}' #prints "Hello {name}"
@FerPerales
FerPerales / gist:3884705
Created October 13, 2012 13:57
Delimiters
puts %Q/This is the same as a double-quoted string./
puts %Q/This is also the same as a double-quoted string./
puts %q/And this is the same as a single-quoted string/
puts %Q*This is the same as a double-quoted string*
puts %Q!This is also the same as a double-quoted string!
puts %q(And this is the same as a single-quoted string)
puts %Q?This is the same as a double-quoted string?
puts %Q/This is also the same as a double-quoted string./
puts %q/And this is the same as a single-quoted string/
puts %Q#This is the same as a double-quoted string#
@FerPerales
FerPerales / gist:3884684
Created October 13, 2012 13:48
Evaluations
class RubyMeeting
attr_accessor :name, :number, :date
def initialize( aName, aNumber, aDate = Time.now )
@name = aName
@number = aNumber
@date = aDate
end
def attendance
@FerPerales
FerPerales / gist:3884724
Created October 13, 2012 14:05
Backquote
puts(`ls`)
puts(%x/clear/)
puts(%x{su -})
@FerPerales
FerPerales / gist:3884809
Created October 13, 2012 14:24
Concatenation
s = "Hello " << "rubyCUCEI"
puts s # Hello rubyCUCEI
s = "Hello " + "rubyCUCEI"
puts s # Hello rubyCUCEI
s = "Hello " "rubyCUCEI"
puts s # Hello rubyCUCEI
@FerPerales
FerPerales / gist:3884835
Created October 13, 2012 14:32
Special concat
#s = "Hello " + 64 #Error: can't convert Fixnum into String
s = "Hello " << 64
puts s # Hello @
s = "Hello " << 64.to_s
puts s # Hello 64
@FerPerales
FerPerales / gist:3884860
Created October 13, 2012 14:42
Mutable strings
s = "Hello "
s = s + "rubyCUCEI!" #New object "Hello rubyCUCEI!"
puts s
s = s.capitalize #New object "Hello rubycucei!"
puts s
r = "Hello "
r += "rubyCUCEI!" #New object "Hello rubyCUCEI!"
puts r
r.capitalize! #Same object "Hello rubycucei"
puts r
@FerPerales
FerPerales / gist:3921738
Created October 20, 2012 02:22
String as array
s = "OMG!"
puts s[2]
#Ruby 1.8 displays 71; Ruby 1.9 displays G
@FerPerales
FerPerales / gist:3921743
Created October 20, 2012 02:25
Workarroung Ruby 1.8
s = "OMG!"
puts s[2,1]
#Ruby 1.8 now displays G
@FerPerales
FerPerales / gist:3921755
Created October 20, 2012 02:33
Workarround Ruby 1.9
s = "OMG!"
puts s[2].ord
#Ruby 1.9 now displays 71