bachpx195 / experience

kiến thức thì vô tận.
1 stars 0 forks source link

EXPERIENCE RUBY #26

Closed bachpx195 closed 3 years ago

bachpx195 commented 7 years ago

My favorite language

link

bachpx195 commented 7 years ago

Một số khái niệm trong ruby

&block

Splat!

Truyền nhiều biến vào method với *agrument

def what_up(greeting, *bros)
  bros.each { |bro| puts "#{greeting}, #{bro}!" }
end

what_up("What up", "Justin", "Ben", "Kevin Sorbo")

What up, Justin! What up, Ben! What up, Kevin Sorbo! ["Justin", "Ben", "Kevin Sorbo"]

bachpx195 commented 7 years ago

Functions helper

Repleace String

print "Who are you?"
user_input = gets.chomp
user_input.downcase!

if user_input.include? "s"
    user_input.gsub!(/s/,"th")
end

Who are you? bachs "bachth"

Insert into array

Get random number array for test

Array.new(4) { rand(1...9) }