From 5e7c70e2b56a5da70f2daf8f074ecc255ebc5f07 Mon Sep 17 00:00:00 2001 From: hundredbillion Date: Fri, 3 Oct 2025 13:34:31 -0400 Subject: [PATCH 1/5] add javascript page --- .../ruby-from-other-languages/index.md | 1 + .../to-ruby-from-javascript/index.md | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md diff --git a/en/documentation/ruby-from-other-languages/index.md b/en/documentation/ruby-from-other-languages/index.md index 3d68ed59a7..9d06edfe1d 100644 --- a/en/documentation/ruby-from-other-languages/index.md +++ b/en/documentation/ruby-from-other-languages/index.md @@ -24,6 +24,7 @@ with. * [To Ruby From Perl](to-ruby-from-perl/) * [To Ruby From PHP](to-ruby-from-php/) * [To Ruby From Python](to-ruby-from-python/) +* [To Ruby From Javascript](to-ruby-from-javascript/) ## Important Language Features And Some Gotchas diff --git a/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md b/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md new file mode 100644 index 0000000000..02993c7ff4 --- /dev/null +++ b/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md @@ -0,0 +1,70 @@ +--- +layout: page +title: "To Ruby From Javascript" +lang: en +--- + +JavaScript is a ubiquitous programming language, primarily known for web +development but also used for server-side development with Node.js. Going +from JavaScript to Ruby, you'll find Ruby has more structured syntax and +strong object-oriented principles, but you'll also discover Ruby's focus +on developer happiness and expressiveness. + +### Similarities + +As with JavaScript, in Ruby,... + +* There's an interactive prompt (called `irb`). +* Objects are dynamically typed. +* Functions are first-class objects. +* There are no special line terminators (except the usual newline). +* You can define functions inside other functions. +* Arrays and objects (hashes in Ruby) are core data structures. +* There is excellent support for functional programming with blocks, + iterators, and higher-order functions. +* Variables are dynamically typed—you don't declare their types. +* Both support closures and can capture variables from their + surrounding scope. +* Regular expressions are built into the language. +* Both languages are interpreted, not compiled. + + +### Differences + +Unlike JavaScript, in Ruby,... + +* You don't need to worry about browser compatibility—Ruby runs + consistently across platforms. +* Everything is an object, including numbers and basic types. + `5.times { puts "Hello" }` is valid Ruby. +* There's no concept of `undefined`. Ruby uses `nil` instead of both + `null` and `undefined`. +* Functions are called methods, and you typically call them on objects. +* There's `public`, `private`, and `protected` for method visibility, + rather than relying on conventions or closures for privacy. +* Ruby has class-based inheritance with single inheritance plus mixins, + rather than JavaScript's prototype-based inheritance. +* Variables have different scopes indicated by their prefix (`@instance`, + `@@class`, `$global`) rather than using `var`, `let`, or `const`. +* String interpolation uses `#{}` syntax: `"Hello #{name}"` instead of + template literals or concatenation. +* Ruby blocks with `do...end` or `{...}` are more powerful than + JavaScript arrow functions and are used extensively for iteration. +* Minimal punctuation: semicolons are optional and rarely used; blocks are delimited with `end` (or `do...end`) rather than `{}`. +* It's `elsif` instead of `else if`. +* Ruby has symbols (`:symbol`) which are immutable strings often used + as identifiers. +* No type coercion surprises—Ruby is more predictable about type + conversions. +* Ruby methods can end with `?` (for predicates) or `!` (for + destructive operations). +* Parentheses for method calls are usually optional. +* You use `require` or `require_relative` instead of `import` or + `require()`. +* Classes are defined with `class...end` blocks rather than constructor + functions or class expressions. +* Ruby has built-in support for operator overloading. +* When tested for truth, only `false` and `nil` are falsy. Everything + else is truthy (including `0`, `""`, and `[]`). +* Ruby has extensive metaprogramming capabilities—you can easily + modify classes and objects at runtime. From 75a794b1a83bf7112bb298520cbb3167a2e528bf Mon Sep 17 00:00:00 2001 From: david lee Date: Fri, 3 Oct 2025 14:04:43 -0400 Subject: [PATCH 2/5] Update en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md spelling change Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../ruby-from-other-languages/to-ruby-from-javascript/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md b/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md index 02993c7ff4..7969c44499 100644 --- a/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md +++ b/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md @@ -1,6 +1,6 @@ --- layout: page -title: "To Ruby From Javascript" +title: "To Ruby From JavaScript" lang: en --- From c26114cb0c3e9c2580c8b9211c33d7fa74f8b8fc Mon Sep 17 00:00:00 2001 From: david lee Date: Fri, 3 Oct 2025 14:04:57 -0400 Subject: [PATCH 3/5] Update en/documentation/ruby-from-other-languages/index.md spelling change Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- en/documentation/ruby-from-other-languages/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/en/documentation/ruby-from-other-languages/index.md b/en/documentation/ruby-from-other-languages/index.md index 9d06edfe1d..1d649b9ddc 100644 --- a/en/documentation/ruby-from-other-languages/index.md +++ b/en/documentation/ruby-from-other-languages/index.md @@ -24,7 +24,7 @@ with. * [To Ruby From Perl](to-ruby-from-perl/) * [To Ruby From PHP](to-ruby-from-php/) * [To Ruby From Python](to-ruby-from-python/) -* [To Ruby From Javascript](to-ruby-from-javascript/) +* [To Ruby From JavaScript](to-ruby-from-javascript/) ## Important Language Features And Some Gotchas From ced4a243796e0334dcf670b9b0086bbf676af8e8 Mon Sep 17 00:00:00 2001 From: david lee Date: Fri, 3 Oct 2025 14:42:40 -0400 Subject: [PATCH 4/5] Update en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md this is a good clarification Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../ruby-from-other-languages/to-ruby-from-javascript/index.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md b/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md index 7969c44499..fed37edc52 100644 --- a/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md +++ b/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md @@ -59,8 +59,7 @@ Unlike JavaScript, in Ruby,... * Ruby methods can end with `?` (for predicates) or `!` (for destructive operations). * Parentheses for method calls are usually optional. -* You use `require` or `require_relative` instead of `import` or - `require()`. +* You use `require` or `require_relative` in Ruby, whereas in JavaScript you use ES6 `import` (or Node.js's `require()`). * Classes are defined with `class...end` blocks rather than constructor functions or class expressions. * Ruby has built-in support for operator overloading. From 60f289c9f90668448bed8e86bf1041273ea9e6ed Mon Sep 17 00:00:00 2001 From: david lee Date: Fri, 3 Oct 2025 14:42:53 -0400 Subject: [PATCH 5/5] Update en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md Yes I'll accept this Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../ruby-from-other-languages/to-ruby-from-javascript/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md b/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md index fed37edc52..0abeaf1acb 100644 --- a/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md +++ b/en/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md @@ -50,7 +50,8 @@ Unlike JavaScript, in Ruby,... template literals or concatenation. * Ruby blocks with `do...end` or `{...}` are more powerful than JavaScript arrow functions and are used extensively for iteration. -* Minimal punctuation: semicolons are optional and rarely used; blocks are delimited with `end` (or `do...end`) rather than `{}`. +* Minimal punctuation: semicolons are optional and rarely used. +* Blocks are delimited with `end` (or `do...end`) rather than `{}`. * It's `elsif` instead of `else if`. * Ruby has symbols (`:symbol`) which are immutable strings often used as identifiers.