Skip to content

Commit

Permalink
T-31 Alias [] for new (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Mar 5, 2020
1 parent d2a607c commit 56fd14a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/basic_temperature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class InvalidNumericOrTemperatureError < StandardError; end

attr_reader :degrees, :scale

class << self
alias [] new
end

def initialize(*positional_arguments, **keyword_arguments)
assert_either_positional_arguments_or_keyword_arguments!(positional_arguments, keyword_arguments)

Expand Down
6 changes: 6 additions & 0 deletions spec/basic_temperature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
end
end

describe '.[]' do
it 'is an alias of .new' do
Temperature.method(:[]) == Temperature.method(:new)
end
end

describe '#to_celsius' do
context 'when temperature scale is celsius' do
it 'returns temperature in celsius' do
Expand Down

0 comments on commit 56fd14a

Please sign in to comment.