class Menu attr_accessor :name attr_accessor :price def initialize(name:, price:) self.name = name self.price = price end def info return "#{self.name} #{self.price}vnd" end end class Drink < Menu attr_accessor :size # initializeメソッドをオーバーライドする # nameと priceは superとする def initialize(name:, price:, size:) super(name: name, price: price) self.size = size end def info return "#{self.name} #{self.price}vnd (#{self.size}サイズ)" end end menu1 = Menu.new(name: "Phở", price: 30000) menu2 = Menu.new(name: "Bún chả", price: 40000) menu3 = Menu.new(name: "Bánh mì", price: 20000) # Drinkの変数を定義してください drink1 = Drink.new(name: "Coke", price: 20000, size: "M") drink2 = Drink.new(name: "Pepsi", price: 15000, size: "L") # 変数menusを定義して配列を代入してください menus = [menu1, menu2, menu3, drink1, drink2] index = 0 menus.each do |menu| puts "#{index}. #{menu.info}" index += 1 end puts "--------------------------------" puts "メニューの番号を選択してください" order = gets.to_i selected_menu = menus[order] puts "選択されたメニュー: #{selected_menu.name}" puts "お会計は #{selected_menu.price} です "
# Hello World Program in Ruby def total(one,five,ten,twenty, fifty, hundred) none = 1 * one nfive = 5 * five nten = 10 * ten ntwenty = 20 * twenty nfifty = 50 * fifty nhundred = 100 * hundred puts none + nfive + nten + ntwenty + nfifty + nhundred end total(0, 20, 11, 22, 1, 12)
4) Can you vote? print "Let's check your age: " age = Integer(gets) def can_you_vote?(age) if age >= 18 puts "True" else puts "False" end end can_you_vote?(age) ----------------------------------------------------------------------------- 5) EvenNumber print "Choose a number: " num = gets def even_number(num) for num in 50..90 if num.even? puts num else () end end even_number(num) ----------------------------------------------------------------------------- 6) Age next year print "What's your age today ?" age = gets def next_year(age) puts "Next year I'll be #{age + 1} years old" end next_year(age) ----------------------------------------------------------------------------- 7) Playlist Array my_array = ["Hotel California", "Bohemian Rhapsody", "Stairway To Heaven"] print "Your favorite song?" song = String(gets) def add_song_to_playlist(song) my_array = ["Hotel California", "Bohemian Rhapsody", "Stairway To Heaven"] << song puts my_array end add_song_to_playlist(song) #my_array << song was not working, the other method i put was quicker, there are others possibilities but lack of time. ----------------------------------------------------------------------------- 8) Odd or event ? print "Choose a number" num = Integer(gets) def odd_or_even(num) puts "even" if num.even? puts "odd" if num.odd? end odd_or_even(num) ----------------------------------------------------------------------------- 9) Palindrome Word print "Write a single word please here : " word = String(gets) def palindrome?(word) word.downcase! unless !word.include? " " puts "Write a single word and run again the program !" else puts "True" if word == word.reverse puts "False" if word != word.reverse end end palindrome?(word) -----------------------------------------------------------------------------
4) Can you vote? print "Let's check your age: " age = Integer(gets) def can_you_vote?(age) if age >= 18 puts "True" else puts "False" end end can_you_vote?(age) ----------------------------------------------------------------------------- 5) EvenNumber print "Choose a number: " num = gets def even_number(num) for num in 50..90 if num.even? puts num else () end end even_number(num) ----------------------------------------------------------------------------- 6) Age next year print "What's your age today ?" age = gets def next_year(age) puts "Next year I'll be #{age + 1} years old" end next_year(age) ----------------------------------------------------------------------------- 7) Playlist Array my_array = ["Hotel California", "Bohemian Rhapsody", "Stairway To Heaven"] print "Your favorite song?" song = String(gets.chomp!) def add_song_to_playlist(song) my_array = ["Hotel California", "Bohemian Rhapsody", "Stairway To Heaven"] << song puts my_array end add_song_to_playlist(song) #my_array << song was not working, the other method i put was quicker, there are others possibilities but lack of time. ----------------------------------------------------------------------------- 8) Odd or event ? print "Choose a number" num = Integer(gets) def odd_or_even(num) puts "even" if num.even? puts "odd" if num.odd? end odd_or_even(num) ----------------------------------------------------------------------------- 9) Palindrome Word print "Write a single word please here : " word = String(gets) def palindrome?(word) word.downcase! unless !word.include? " " puts "Write a single word and run again the program !" else puts "True" if word == word.reverse puts "False" if word != word.reverse end end palindrome?(word) ---------------------------------------------------------------------------------
hotfix_branch = "hotfix/2.34.1" release_branch = "release/2.35.0" master_branch = "master" feature_branch = "1923-core-something" def check_branch(source_branch, squash) is_release_branch = (/^(release\/)(\d+).(\d+).(\d+)$/.match(source_branch)) is_hotfix_branch = (/^(hotfix\/)(\d+).(\d+).(\d+)$/.match(source_branch)) is_master_branch = source_branch == "master" unless squash || is_release_branch || is_hotfix_branch || is_master_branch puts "failed" else puts "passed" end end puts "Hotfix, squash = true => passed" check_branch(hotfix_branch, true) puts "Hotfix, squash = false => passed" check_branch(hotfix_branch, false) puts "Release, squash = true => passed" check_branch(release_branch, true) puts "Release, squash = true => passed" check_branch(release_branch, false) puts "Master, squash = true => passed" check_branch(master_branch, true) puts "Master, squash = false => passed" check_branch(master_branch, false) puts "Feature, squash = true => passed" check_branch(feature_branch, true) puts "Feature, squash = false => failed" check_branch(feature_branch, false)
hotfix_branch = "hotfix/asf" release_branch = "release/asf" master_branch = "master" feature_branch = "1923_core_something" def check_branch(source_branch, squash) is_release_branch = (/^(release\/).*$/.match(source_branch)) is_hotfix_branch = (/^(hotfix\/).*$/.match(source_branch)) is_master_branch = source_branch == "master" #puts "🏸 Please check the squash option in the merge request settings. Think about our nice changelog 🙏" unless is_release_branch || is_hotfix_branch || is_master_branch || squash unless squash || is_release_branch || is_hotfix_branch || is_master_branch puts "🏸 Please check the squash option in the merge request settings. Think about our nice changelog 🙏" else puts "MR ok!" end end puts "* Checking hotfix branch with squash" check_branch(hotfix_branch, true) puts "* Checking hotfix branch without squash" check_branch(hotfix_branch, false) puts "* Checking release branch with squash" check_branch(release_branch, true) puts "* Checking release branch without squash" check_branch(release_branch, false) puts "* Checking master branch with squash" check_branch(master_branch, true) puts "* Checking master branch without squash" check_branch(master_branch, false) puts "* Checking feature branch with squash" check_branch(feature_branch, true) puts "* Checking feature branch without squash" check_branch(feature_branch, false)
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more