Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andriikot/ruby-methods-vs-js-function
Ruby methods VSJs functio
https://github.com/andriikot/ruby-methods-vs-js-function
Last synced: about 2 months ago
JSON representation
Ruby methods VSJs functio
- Host: GitHub
- URL: https://github.com/andriikot/ruby-methods-vs-js-function
- Owner: AndriiKot
- Created: 2023-03-22T15:53:06.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-03-29T09:06:34.000Z (over 1 year ago)
- Last Synced: 2024-01-09T00:29:42.063Z (12 months ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ruby-methods-VS-Js-functions
Ruby methods VSJs functio#JS
```node
function myFunction1(a,b) {
return a * b
}console.log(myFunction1(3,5)) // 15
```
#Ruby
```ruby
def myMethod1 a,b
a * b
endp myMythods1 3,5 # 15
```#JS
```node
function myFunction2(a,b) {return a / b}console.log(8,4) // 2
```#Ruby
```ruby
def myMethod2(a,b) = a / bp myMethod1 8,4 # 2
```
____
#JS
```node
function myFunction3(a,b) {return a + b}
console.log(myFunction3()) // NaN !!!
```
#Ruby
```ruby
def myMethod3(a,b) = a + b
p myMethod3 # wrong number of arguments(given 0 , exended 2)
def myMethod3(a = nil,b = a) = (return a + b if (a && b); 0 / 0.0)
p myMethod3 # NaN imitation js function !!!
```
____
#JS
```node
let x = function(a,b){return a - b}
let y = x(15,5)
console.log(y) // 10
```
#Ruby
```rubydef myMethod5(a = nil,b = a) = proc{ |a,b| a - b if (a && b)} # imitation js function
x = myMethod5 # Proc
z = x[15,5]
p z # 10z = x # Proc
p z[] # nil
p z[23,16] # 7
```