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
class Car | |
attr_accessor :colour | |
attr_reader :make | |
def initialize(make, colour) | |
@make = make | |
@colour = colour | |
end | |
def car_start |
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
colours = %w(red green blue yellow purple) | |
colours.each do |colour| | |
puts colour + " " + "balloons" | |
end |
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
class Computer | |
def initialize(brand) | |
@brand = brand | |
@power = false | |
end | |
def power_on | |
@power = true | |
end |
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
# Goal: Starting with shopping_centre, get back the string '29%' | |
require 'pry' | |
squash = { | |
name: 'squash', | |
length: 15, | |
nutrients: [ | |
{ | |
vitamin: 'A', |
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
def c_to_f | |
puts "enter the celcius you'd like to convert" | |
c = gets.chomp.to_i | |
result = c * (9 / 5.0) + 32 | |
return result | |
end | |
p c_to_f |
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
# 1. Extract the string 'lemon' and give its data type | |
fruit = ['apple', 'orange', 'lemon'] | |
p fruit[2] | |
# string | |
# 2. Extract the brand ('iPhone'), and the weight, and give the datatype | |
phone = { | |
brand: 'iPhone', | |
price: 90000, |
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
class Car | |
attr_reader :brand | |
@@cars = 0 | |
def self.number_of_cars | |
return @@cars | |
end | |
def initialize(brand) | |
@brand = brand |
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
# In your Ruby file, run a while loop that presents these options, gets input from a user (as a number), and then acts on this input. | |
# For example, if the user selects 1, you will add a dish, and so you will take further input from the user and add that into an array. | |
# Do a similar job for the rest of the options with the appropriate inputs from the user, or the appropriate output. | |
# write a case statement with the different options | |
menu = [{name: "beef", price: 400}, {name: "stew", price: 300}, {name: "hamburger", price: 500}] | |
input = nil | |
orders = [] |
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
def sum_with_for(min, max) | |
total = 0 | |
# we create the total variable outside of the loop so that we can use it for the sum, we add to it in each iteration | |
return -1 if min > max | |
# we can put the return -1 here as we can check the values at this point even before the first loop | |
for i in (min..max) do | |
total += i | |
end | |
# for each loop we add total to i (i represents the iteration) | |
# example => total = total + 1 on the first loop (total is set at zero), then total = total + 2 on the second loop (total will now be 1 after that first iteration) |
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
require 'forecast_io' | |
ForecastIO.api_key = ENV.fetch('DARK_SKY_API_KEY') | |
puts ENV['DARK_SKY_API_KEY'] | |
lat = -37.815712 | |
long = 144.955546 | |
forecast = ForecastIO.forecast(lat, long) | |
puts forecast[:hourly][:data][0][:summary] | |
# puts "long = #{forecast.longitude}" |