Skip to content

Commit

Permalink
making arrays first and last more relaxed as well as allow nil compar…
Browse files Browse the repository at this point in the history
…ison
  • Loading branch information
khash committed Sep 3, 2018
1 parent 499ab29 commit ef6dd9c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
c66-copper (0.0.4)
c66-copper (0.0.5)
colorize (~> 0.8)
ipaddress (~> 0.8)
json (~> 1.4)
Expand Down
3 changes: 2 additions & 1 deletion lib/copper/comparison.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def value(vars = {})
comp_op = elements[1].value(vars)
rhs = elements[2].value(vars)

raise ParseError, "cannot compare nil" if rhs.nil? || lhs.nil?
return true if rhs.nil? && lhs.nil?
return false if rhs.nil? || lhs.nil?

puts "[DEBUG] Comparing #{lhs} (#{lhs.class.name}) #{comp_op} #{rhs} (#{rhs.class.name})" if $debug
begin
Expand Down
4 changes: 2 additions & 2 deletions lib/copper/data_types/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ def count
end

def first
raise RuntimeError, "cannot call first on an empty array" if @value.empty?
return nil if @value.empty?
return @value.first
end

def last
raise RuntimeError, "cannot call last on an empty array" if @value.empty?
return nil if @value.empty?
return @value.last
end

Expand Down
2 changes: 1 addition & 1 deletion lib/copper/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Copper
VERSION = '0.0.5'
VERSION = '0.0.6'
COPYRIGHT_MESSAGE = "(c) 2018 Cloud66 Inc."
APP_NAME = 'Copper'
end

0 comments on commit ef6dd9c

Please sign in to comment.