Skip to content

Commit

Permalink
Added hash function to int class
Browse files Browse the repository at this point in the history
  • Loading branch information
Onur Karaman committed Mar 22, 2012
1 parent 812a7e9 commit 80304bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/builtin/integer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ class Int extends Num
new Int @__floordiv__ operand
else
super operand

# http://effbot.org/zone/python-hash.htm
__hash__: ->
if @value == -1
return new Int(-2)
return @

__invert__: ->
__invert__: ->
new Int ~@value

__lshift__: (operand) ->
Expand Down Expand Up @@ -54,4 +60,4 @@ class Int extends Num
if issubinstance operand, @
new Int @value ^ operand.value
else
super operand
super operand
4 changes: 2 additions & 2 deletions src/builtin/primitive.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Primitive extends Obj

__le__: (operand) ->
if issubinstance operand, @
new Bool <= operand.value
new Bool @value <= operand.value
else
super operand

Expand Down Expand Up @@ -109,4 +109,4 @@ class Primitive extends Obj
# **Consideration** What is the difference between __repr__ and __str__?
# How does this affect console.log / print / concatenation?
__str__: ->
new Str @value.toString()
new Str @value.toString()

0 comments on commit 80304bb

Please sign in to comment.