Skip to content

Commit ef6dd9c

Browse files
committed
making arrays first and last more relaxed as well as allow nil comparison
1 parent 499ab29 commit ef6dd9c

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
c66-copper (0.0.4)
4+
c66-copper (0.0.5)
55
colorize (~> 0.8)
66
ipaddress (~> 0.8)
77
json (~> 1.4)

lib/copper/comparison.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ def value(vars = {})
66
comp_op = elements[1].value(vars)
77
rhs = elements[2].value(vars)
88

9-
raise ParseError, "cannot compare nil" if rhs.nil? || lhs.nil?
9+
return true if rhs.nil? && lhs.nil?
10+
return false if rhs.nil? || lhs.nil?
1011

1112
puts "[DEBUG] Comparing #{lhs} (#{lhs.class.name}) #{comp_op} #{rhs} (#{rhs.class.name})" if $debug
1213
begin

lib/copper/data_types/array.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ def count
77
end
88

99
def first
10-
raise RuntimeError, "cannot call first on an empty array" if @value.empty?
10+
return nil if @value.empty?
1111
return @value.first
1212
end
1313

1414
def last
15-
raise RuntimeError, "cannot call last on an empty array" if @value.empty?
15+
return nil if @value.empty?
1616
return @value.last
1717
end
1818

lib/copper/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Copper
2-
VERSION = '0.0.5'
2+
VERSION = '0.0.6'
33
COPYRIGHT_MESSAGE = "(c) 2018 Cloud66 Inc."
44
APP_NAME = 'Copper'
55
end

0 commit comments

Comments
 (0)