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 'Enter your name: ' #Fer | |
name = gets() | |
puts "Hello #{name}" #prints "Hello Fer" | |
puts 'Hello #{name}' #prints "Hello {name}" |
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
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# |
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
class RubyMeeting | |
attr_accessor :name, :number, :date | |
def initialize( aName, aNumber, aDate = Time.now ) | |
@name = aName | |
@number = aNumber | |
@date = aDate | |
end | |
def attendance |
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
puts(`ls`) | |
puts(%x/clear/) | |
puts(%x{su -}) |
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
s = "Hello " << "rubyCUCEI" | |
puts s # Hello rubyCUCEI | |
s = "Hello " + "rubyCUCEI" | |
puts s # Hello rubyCUCEI | |
s = "Hello " "rubyCUCEI" | |
puts s # Hello rubyCUCEI |
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
#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 |
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
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 |
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
s = "OMG!" | |
puts s[2] | |
#Ruby 1.8 displays 71; Ruby 1.9 displays G |
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
s = "OMG!" | |
puts s[2,1] | |
#Ruby 1.8 now displays G |
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
s = "OMG!" | |
puts s[2].ord | |
#Ruby 1.9 now displays 71 |