Ruby strings

""
"ab" + "cd"
name="Ikbhal"
last="shaik"
full_name = "#{name} #{last}"
puts "foo"
# is same as
printf "foo\n"


2.2.1 :011 > "ikbhal".length
 => 6 
2.2.1 :012 > "ikbhal".empty?
 => false 
2.2.1 :013 > "".empty?

 => true 

2.2.1 :025 > if s.empty?
2.2.1 :026?>   "The string is empty"
2.2.1 :027?>   else
2.2.1 :028 >     "The string is not empty"
2.2.1 :029?>   end
 => "The string is not empty" 

2.2.1 :030 > nil.to_s
 => "" 
2.2.1 :031 > x =2
 => 2 
2.2.1 :032 > puts x if x<2 span="">
 => nil 

2.2.1 :033 > "ab".nil?
 => false 
2.2.1 :034 > "".nil?
 => false 
2.2.1 :035 > nil.nil?
 => true 

2.2.1 :036 > string = "foobar"
 => "foobar" 
2.2.1 :037 > puts "string is not empty" unless string
 => nil 
2.2.1 :038 > puts "string is not empty" unless string.empty?
string is not empty
 => nil 

No comments:

Post a Comment