Skip to content

Commit

Permalink
float: adds to integer object function (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelPour authored Feb 3, 2022
1 parent a0d4a70 commit 1cf65ea
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`
Converts the float into an integer.


```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

1 comment on commit 1cf65ea

@vercel
Copy link

@vercel vercel bot commented on 1cf65ea Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.