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

Execute Ruby Online

### MAP METHOD

array = ["A", "B", "C"]

puts array.map {|n| n + "!"}
puts array


### SELECT METHOD

numeric_array = [111, 24, 3, 76, 5, 60, 7, 8, 9, 10]
puts "--------------------------------------------"
puts numeric_array.sort {|a, b| b <=> a}
puts 
puts "START"

puts "END"
puts
puts numeric_array.select {|element| element % 2 == 1}


fruits = ["apple", "pinapple"]

puts fruits.map {|element|  element[0].upcase + element[1..-1].downcase}
puts 
result = fruits.map.with_index do |element, index|
     new_word = element[0].upcase + element[1..-1].downcase 
    # "hello!!!"
    new_word * index
end
puts 
puts
puts result

###### MAP BY NAME






word = "Ruslan"
wor = word.split("")
puts wor.reverse.join
 wor.sort! {|x, y| y <=> x}
puts wor.join()

Advertisements
Loading...

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