-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore_item.rb
More file actions
65 lines (48 loc) · 1.91 KB
/
store_item.rb
File metadata and controls
65 lines (48 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Use hashes with symbols to represent the following scenario:
# You are the owner of a store that sells items (you decide what specifically). Each item has various properties such as color, price, etc.
# Represent 3 items using hashes. Each hash should have the same keys with different values.
# # Be sure to use symbols for the keys. Try creating hashes using both types of hash symbol syntaxes. (Ruby syntax {:a => 123} vs. “JavaScript” syntax {a: 123}).
# synth1 = {:brand => "Roland", :polyphony => "Poly", :model => "Juno-106"}
# synth2 = {:brand => "Korg", :polyphony => "Mono", :model => "MS-20"}
# synth3 = {:brand => "Novation", :polyphony => "Poly", :model => "Peak"}
# synth1 = {brand: "Roland", polyphony: "Poly", model: "Juno-106"}
# synth2 = {brand: "Korg", polyphony: "Mono", model: "MS-20"}
# synth3 = {brand: "Novation", polyphony: "Poly", model: "Peak"}
class Synth
attr_reader :brand, :model, :polyphony, :price
attr_writer :price
# def initialize(input_brand,input_model,input_polyphony,input_price)
# @brand = input_brand
# @model = input_model
# @polyphony = input_polyphony
# @price = input_price
# end
# Rewrite your store items using a class with a single options hash in the initialize method.
def initialize(input_options)
@brand = input_options[:brand]
@model = input_options[:model]
@polyphony = input_options[:polyphony]
@price = input_options[:price]
end
# def brand
# @brand
# end
# def model
# @model
# end
# def polyphony
# @polyphony
# end
# def price
# @price
# end
# def price=(input_price)
# @price = input_price
# end
def print_info
puts "The #{brand} #{model} is a #{polyphony} synthesizer and costs $#{price}."
end
end
# synth1 = Synth.new("Roland","Juno-160","polyphonic","2600")
synth1 = Synth.new(brand: "Roland", model: "Juno-160", polyphony: "polyphonic", price: "2600")
synth1.print_info