Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Create sleep timer in Ruby Programming

def timer
  start_time = Time.now
  yield
  puts "Elapsed time: #{Time.now - start_time}s"
end

timer() do
  puts "I'm doing something slow..."
  sleep(15)
  puts "I'm done :)"
end
# => I'm doing somethings slow...
# => I'm done :)
# => Elapsed time: 4s

Ruby_04

# Hello World Program in Ruby
Name="Naresh"
puts Name
Name1="naresh"
puts Name1.upcase()
Name2="NARESH"
puts Name2.downcase()
Name3="         Naresh         "
puts Name3
Name4="         Naresh         "
puts Name4.strip()
Name5="Naresh"
puts Name5.length()
Name6="Naresh"
puts Name6.include? "esh"
Name7="Naresh"
puts Name7.include? "Zim"
Name8="Naresh"
puts Name8[5]
Name9="Naresh"
puts Name9[0,3]
Name10="Naresh"
puts Name10.index("r")
puts "zimbre".upcase()

more hash, array practice and multi line print with one statement

arr_1=["this", "that", "other", "and still, another"]
arr_2=[56, 9, "numbers", "creamy delights"]
test_hash_1={"stone"=>"agate", "animal"=>"capibarra"}

puts
puts test_hash_1
puts test_hash_1["stone"]
puts test_hash_1["animal"]
puts test_hash_1[arr_1] ### This should return an error, as I havent assigned a key to the value of 
### arr_1

puts
test_hash_2={3 => arr_1, 4 => arr_2, "animal" => "capibara", "stone" => "agate"}
puts
puts test_hash_2
puts test_hash_2["animal"]
puts test_hash_2["stone"]
puts test_hash_2[4]
puts test_hash_2[3]
puts
print <<eof
Apparently, a hash key can only be a number or a 
string, and not a letter variable, as letter variables 
return errors, while numbers and strings don't.

  And, it's worth mentioning, that this comment was printed 
  using the 'print <<eof' statement (function?).  'print <<eof'
  maintains formating, like the indent here.
eof

Store multiple arrays under separate hash keys

item_array=["item 1", "item 2", "item 3", "item 4"]
thing_array=["thing 1", "thing 2", "thing 3", "thing 4", "thing 5"]
vox_array=["vox 1", "vox 2", "vox 3", "vox 4", "vox 5"]
multi_array_hash={"item key" => item_array, "thing key" => thing_array, "vox key" => vox_array}

puts item_array
puts
puts thing_array
puts
puts vox_array
puts 
puts multi_array_hash ["item key"]
puts 
puts multi_array_hash ["thing key"]
puts 
puts multi_array_hash ["vox key"]
puts 
puts multi_array_hash

puts multi_array_hash ["item key"], multi_array_hash ["vox key"]

regex-marota-para-locais-e-recursos

text = "Nome do campo1: resposta1 | Nome do campo2: resposta2 | Nome do campo3: resposta3"
groups = text.split(/\s\|\s/)

groups.each do |group|
 if match = group.match(/(.+):\s(.+)/)
   name, value = match.captures

   puts "Name: ‘#{name}‘"
   puts "Value: ‘#{value}’"
 end
end

Execute Ruby Online

a = {"id"=>1, "title"=>"Clipping path", "handle"=>"clipping-path", "quantity"=>15, "categories"=>[{"id"=>1, "sku"=>"CLIPPING-PATH_C1", "title"=>"Category 1", "quantity"=>5, "efficiency"=>90}, {"id"=>2, "sku"=>"CLIPPING-PATH_C2", "title"=>"Category 2", "quantity"=>10, "efficiency"=>95}], "efficiency"=>93}

puts a[:id]

Execute Ruby Online

#require 'date'
def leave_category_calculator(employed_date)
#	@employee = employee_id
	@employed_date = employed_date
	time_worked = Time.now - @employed_date
	days_worked = (time_worked/86400).round    # one day = 86400 seconds	

		if days_worked < 0 
			    category = 0
		   elsif days_worked < 365
		   	    category = 3
		   elsif days_worked > 1825
		   	    category = 1
		   else
		        category = 2
		   	end
		   	
	    if category == 1
			    category_name = "Long-serving Employee"
	    elsif category == 2
		   	    category_name = "Short-serving Employee"
        elsif category == 3
		   	    category_name = "New Employee"
		else category_name = "Invalid"
		   end	
		   
puts category_name
puts days_worked

end
entered_date=Time.new(2019,04,05)
leave_category_calculator(entered_date)
puts Time.now

Execute Ruby Online

# Hello World Program in Ruby
puts "Hello ";

deleteandgsub

a = "MIIDzzCCAregAwIBAgIUKB8mVZw330DkdZsMnBdHrawQ9HgwDQYJKoZIhvcNAQEF\nBQAwQTEMMAoGA1UECgwDbHJtMRUwEwYDVQQLDAxPbmVMb2dpbiBJZFAxGjAYBgNV\rBAMMEU9uZUxv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KDANscm0xFTATBgNVBAsM\r\nDE9uZUxvZ2luIElkUDEaMBgGA1UEAwwRT25lTG9naW4gQWNjb3VudCCCFCgfJlWc\r\nN99A5HWbDJwXR62sEPR4MA4GA1UdDwEB/wQEAwIHgDANBgkqhkiG9w0BAQUFAAOC\r\nAQEAlbEIOJr8jDEvwTqHxCBFTiKpxXdiNQSxBDpntA3deYj1NcyT2FcwxZfxSZRP\r\nl1mtEBGTy0gQYJrUgFm1ZVVkgKgO7t40pQTnWf/32xTLwKRUiCIKuWDoLzOZ+8OF\r\nrXTSPw2Oq/E92TmNQ284UC9Z1bUBN2JMXf9yJFm1EQDXmG6o+ubfIo2/LqH6bNmr\r\nGyteF00gFWNSVKDdwEKQocPLqmZjufMX9JKV9h0p+ZMNs/8MJ3VazJAx2OGo76e0\r\nuC4Hyb2qTCPdKWWRPFP3MrZNBWog0LdmlQs1m6ZMjR+2cPzHxXbfbvrcto5weq3/\r\njf9lOn/H5gv32wWmxF65PeumJg="

puts b.gsub(/\r\n|\r|\n/, '')

https://www.facebook.com/mphoentlelinah.mphoentlelinah

# Hello World Program in Ruby
puts "Hello World!";
puts " iam a hacker"
puts ("we are a hacker")

1 2 3 4 5 6 7 ... 50 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.