Skip to content

Commit

Permalink
float: adds to integer object function
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelPour committed Feb 3, 2022
1 parent 316761f commit 8272f22
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/content/docs/literals/float.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ Returns self



### plz_i()
> Returns `INTEGER`
Returns a integer representation of the float.


```js
🚀 > a = 123.456
=> 123.456
🚀 > a.plz_i()
=> "123"
```


### plz_s()
> Returns `STRING`
Expand Down
14 changes: 14 additions & 0 deletions object/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ func init() {
return NewString(f.toString())
},
},
"plz_i": ObjectMethod{
description: "Converts the float into an integer.",
example: `🚀 > a = 123.456
=> 123.456
🚀 > a.plz_i()
=> "123"`,
method: func(o Object, args []Object) Object {
f := o.(*Float)
return NewInteger(int64(f.Value))
},
returnPattern: [][]string{
[]string{INTEGER_OBJ},
},
},
}
}

Expand Down
1 change: 1 addition & 0 deletions object/float_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestFloatObjectMethods(t *testing.T) {
tests := []inputTestCase{
{`2.1.plz_s()`, "2.1"},
{`2.1.plz_f()`, 2.1},
{`2.1.plz_i()`, 2},
{`10.0.type()`, "FLOAT"},
{`2.2.nope()`, "undefined method `.nope()` for FLOAT"},
{`(2.0.wat().lines().size() == 2.0.methods().size() + 1).plz_s()`, "true"},
Expand Down

0 comments on commit 8272f22

Please sign in to comment.