Convert Figma logo to code with AI

ruby logoruby

The Ruby Programming Language

22,033
5,317
22,033
417

Top Related Projects

3,789

JRuby, an implementation of Ruby on the JVM

5,295

Lightweight Ruby

4,829

Ruby ♥︎ JavaScript

19,409

The Crystal Programming Language

Quick Overview

Ruby/Ruby is the official GitHub repository for the Ruby programming language. It contains the source code, documentation, and development resources for Ruby, a dynamic, object-oriented programming language known for its simplicity and productivity.

Pros

  • Highly readable and expressive syntax
  • Strong community support and extensive ecosystem of libraries (gems)
  • Excellent for rapid prototyping and web development
  • Built-in support for metaprogramming and DSLs

Cons

  • Slower execution speed compared to some compiled languages
  • Global interpreter lock (GIL) limits true multi-threading
  • Memory usage can be high for large applications
  • Version compatibility issues between different Ruby versions

Code Examples

  1. Hello World program:
puts "Hello, World!"
  1. Defining a class and creating an instance:
class Person
  attr_accessor :name, :age

  def initialize(name, age)
    @name = name
    @age = age
  end

  def greet
    puts "Hello, my name is #{@name} and I'm #{@age} years old."
  end
end

person = Person.new("Alice", 30)
person.greet
  1. Working with arrays and blocks:
numbers = [1, 2, 3, 4, 5]
squared = numbers.map { |n| n ** 2 }
puts squared.join(", ")
  1. File I/O example:
File.open("example.txt", "w") do |file|
  file.puts "This is a sample text."
end

content = File.read("example.txt")
puts content

Getting Started

To get started with Ruby, follow these steps:

  1. Install Ruby on your system:

    • For Windows: Use RubyInstaller (https://rubyinstaller.org/)
    • For macOS: Use Homebrew (brew install ruby)
    • For Linux: Use your package manager (e.g., sudo apt-get install ruby)
  2. Verify the installation:

    ruby --version
    
  3. Create a new Ruby file (e.g., hello.rb) and add some code:

    puts "Hello, Ruby!"
    
  4. Run the script:

    ruby hello.rb
    

For more information and documentation, visit the official Ruby website: https://www.ruby-lang.org/

Competitor Comparisons

3,789

JRuby, an implementation of Ruby on the JVM

Pros of JRuby

  • Runs on the Java Virtual Machine (JVM), allowing integration with Java libraries and frameworks
  • Often provides better performance for long-running processes and multi-threaded applications
  • Offers true parallelism through JVM threads, unlike MRI Ruby's Global Interpreter Lock (GIL)

Cons of JRuby

  • Slower startup time compared to MRI Ruby due to JVM initialization
  • Some Ruby gems may not be compatible or require special handling
  • Occasional differences in behavior or feature implementation compared to MRI Ruby

Code Comparison

Ruby (MRI):

# Concurrency example
threads = 5.times.map do
  Thread.new { puts "Hello from thread #{Thread.current.object_id}" }
end
threads.each(&:join)

JRuby:

# Concurrency example with true parallelism
threads = 5.times.map do
  java.lang.Thread.new { puts "Hello from thread #{java.lang.Thread.currentThread.getId}" }
end
threads.each(&:join)

In this example, JRuby can leverage true parallelism through Java threads, potentially offering better performance for concurrent operations compared to MRI Ruby's GIL-limited threads.

5,295

Lightweight Ruby

Pros of mruby

  • Lightweight and embeddable, ideal for resource-constrained environments
  • Designed for easy integration into C programs
  • Faster startup time and lower memory footprint

Cons of mruby

  • Limited standard library compared to Ruby
  • Not all Ruby gems are compatible with mruby
  • Fewer language features and optimizations

Code Comparison

Ruby:

# Ruby example
class Greeter
  def initialize(name)
    @name = name
  end

  def greet
    puts "Hello, #{@name}!"
  end
end

Greeter.new("World").greet

mruby:

# mruby example
class Greeter
  def initialize(name)
    @name = name
  end

  def greet
    puts "Hello, #{@name}!"
  end
end

Greeter.new("World").greet

The basic syntax and structure are identical in this simple example. However, mruby may have limitations with more complex Ruby features or certain standard library methods.

Summary

Ruby is a full-featured, general-purpose programming language, while mruby is a lightweight implementation designed for embedding. mruby sacrifices some features and compatibility for a smaller footprint and easier integration with C programs. The choice between the two depends on the specific requirements of your project, such as resource constraints, embedding needs, and required language features.

4,829

Ruby ♥︎ JavaScript

Pros of Opal

  • Allows running Ruby code in web browsers
  • Enables Ruby developers to write front-end code without learning JavaScript
  • Smaller community size may lead to faster decision-making and implementation of new features

Cons of Opal

  • Limited compatibility with Ruby's standard library and some gems
  • Performance may be slower than native JavaScript for complex operations
  • Smaller ecosystem and community support compared to Ruby

Code Comparison

Ruby:

def greet(name)
  puts "Hello, #{name}!"
end

greet("World")

Opal:

def greet(name)
  `console.log("Hello, " + #{name} + "!")`
end

greet("World")

The main difference in this example is that Opal uses backticks to directly interact with JavaScript's console.log function, while Ruby uses the native puts method for output. This demonstrates how Opal bridges Ruby syntax with JavaScript functionality for browser-based execution.

Both Ruby and Opal aim to provide a developer-friendly language experience, but they serve different purposes. Ruby is a general-purpose language with a wide range of applications, while Opal focuses on bringing Ruby-like syntax to web development, allowing developers to write Ruby code that compiles to JavaScript for browser execution.

19,409

The Crystal Programming Language

Pros of Crystal

  • Significantly faster execution speed due to compilation to native code
  • Static typing for improved type safety and earlier error detection
  • Syntax very similar to Ruby, making it easy for Ruby developers to transition

Cons of Crystal

  • Smaller ecosystem with fewer libraries and tools compared to Ruby
  • Less mature and stable, with potential for breaking changes
  • Limited platform support, primarily focused on Unix-like systems

Code Comparison

Ruby:

def fibonacci(n)
  return n if n <= 1
  fibonacci(n - 1) + fibonacci(n - 2)
end

puts fibonacci(10)

Crystal:

def fibonacci(n : Int32) : Int32
  return n if n <= 1
  fibonacci(n - 1) + fibonacci(n - 2)
end

puts fibonacci(10)

The Crystal version includes type annotations for improved performance and safety, while maintaining a nearly identical syntax to Ruby. This demonstrates Crystal's goal of being a statically-typed language with Ruby-like syntax, offering potential performance benefits while remaining familiar to Ruby developers.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Actions Status: MinGW Actions Status: RJIT Actions Status: Ubuntu Actions Status: Windows Travis Status

What is Ruby?

Ruby is an interpreted object-oriented programming language often used for web development. It also offers many scripting features to process plain text and serialized files, or manage system tasks. It is simple, straightforward, and extensible.

Features of Ruby

  • Simple Syntax
  • Normal Object-oriented Features (e.g. class, method calls)
  • Advanced Object-oriented Features (e.g. mix-in, singleton-method)
  • Operator Overloading
  • Exception Handling
  • Iterators and Closures
  • Garbage Collection
  • Dynamic Loading of Object Files (on some architectures)
  • Highly Portable (works on many Unix-like/POSIX compatible platforms as well as Windows, macOS, etc.) cf. https://docs.ruby-lang.org/en/master/maintainers_md.html#label-Platform+Maintainers

How to get Ruby

For a complete list of ways to install Ruby, including using third-party tools like rvm, see:

https://www.ruby-lang.org/en/downloads/

You can download release packages and the snapshot of the repository. If you want to download whole versions of Ruby, please visit https://www.ruby-lang.org/en/downloads/releases/.

Download with Git

The mirror of the Ruby source tree can be checked out with the following command:

$ git clone https://github.com/ruby/ruby.git

There are some other branches under development. Try the following command to see the list of branches:

$ git ls-remote https://github.com/ruby/ruby.git

You may also want to use https://git.ruby-lang.org/ruby.git (actual master of Ruby source) if you are a committer.

How to build

See Building Ruby

Ruby home page

https://www.ruby-lang.org/

Documentation

Mailing list

There is a mailing list to discuss Ruby. To subscribe to this list, please send the following phrase:

join

in the mail subject (not body) to the address ruby-talk-request@ml.ruby-lang.org.

Copying

See the file COPYING.

Feedback

Questions about the Ruby language can be asked on the Ruby-Talk mailing list or on websites like https://stackoverflow.com.

Bugs should be reported at https://bugs.ruby-lang.org. Read "Reporting Issues" for more information.

Contributing

See "Contributing to Ruby", which includes setup and build instructions.

The Author

Ruby was originally designed and developed by Yukihiro Matsumoto (Matz) in 1995.

matz@ruby-lang.org