This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dice Betting Game, https://opalrb.com/try/ | |
bank = 100; | |
while bank > 0 do | |
bet = `prompt("Place your bet")`.to_i | |
dice1 = (rand * 6).ceil | |
dice2 = (rand * 6).ceil | |
outcome = dice1 == dice2 | |
bank += bet if outcome | |
bank -= bet unless outcome | |
puts "Numbers are: #{dice1} #{dice2}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate an Unix timestamp in Ruby | |
# If you don't want to use: | |
Time.now.strftime("%s") | |
# or | |
Time.now.to_i | |
# Then you can also alias the to_i method: | |
Time.alias_method :unix_timestamp, :to_i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://opalrb.com/try/ | |
# Console Calendar | |
DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
CURRENT_DAY_HIGHLIGHTER = " ✅" | |
HIGHLIGHT_CURRENT_DAY = true | |
def days_in_month(month) | |
return 29 if Time.now.month == 2 | |
DAYS_IN_MONTH[month] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dice Betting Game, https://opalrb.com/try/ | |
require "native" | |
bank = 100; | |
while bank > 0 do | |
bet = $$.prompt("Place your bet").to_i | |
dice1 = (rand * 6).ceil | |
dice2 = (rand * 6).ceil | |
outcome = dice1 == dice2 |
OlderNewer