- Notifications
You must be signed in to change notification settings - Fork644
Issue #2767: Add To Ruby From Javascript#3632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
HundredBillion wants to merge6 commits intoruby:masterChoose a base branch fromHundredBillion:to-ruby-from-javascript-2767
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes from3 commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
5e7c70e add javascript page
HundredBillion75a794b Update en/documentation/ruby-from-other-languages/to-ruby-from-javasc…
HundredBillionc26114c Update en/documentation/ruby-from-other-languages/index.md
HundredBillionced4a24 Update en/documentation/ruby-from-other-languages/to-ruby-from-javasc…
HundredBillion60f289c Update en/documentation/ruby-from-other-languages/to-ruby-from-javasc…
HundredBillion848b1fd Merge branch 'master' into to-ruby-from-javascript-2767
HundredBillionFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletionsen/documentation/ruby-from-other-languages/to-ruby-from-javascript/index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 `{}`. | ||
HundredBillion marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| * 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()`. | ||
HundredBillion marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| * 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. | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.