Th?nk And Grow - Ruby - Ruby https://blog.thnkandgrow.com/category/ruby/ Let's Do It! Mon, 18 Nov 2024 01:12:07 +0000 vi hourly 1 https://wordpress.org/?v=6.9.4 https://d1gj38atnczo72.cloudfront.net/wp-content/uploads/2024/04/18114102/cropped-thnkandgrow-logo-32x32.jpg Th?nk And Grow - Ruby - Ruby https://blog.thnkandgrow.com/category/ruby/ 32 32 Top 10 secrets of Ruby https://blog.thnkandgrow.com/top-10-secrets-of-ruby/ Mon, 18 Nov 2024 01:11:16 +0000 https://blog.thnkandgrow.com/?p=1858 The “secret” of Ruby lies in its philosophy and design principles, which prioritize developer happiness and code simplicity. Here’s a breakdown of what makes Ruby truly unique and powerful: 1. Developer-Centric Philosophy Ruby was designed by Yukihiro Matsumoto (Matz) with one primary goal: to make programming enjoyable for developers. Unlike many languages that focus solely […]

The post Top 10 secrets of Ruby appeared first on Th?nk And Grow.

]]>
The “secret” of Ruby lies in its philosophy and design principles, which prioritize developer happiness and code simplicity. Here’s a breakdown of what makes Ruby truly unique and powerful:


1. Developer-Centric Philosophy

Ruby was designed by Yukihiro Matsumoto (Matz) with one primary goal: to make programming enjoyable for developers. Unlike many languages that focus solely on performance or strict rules, Ruby prioritizes human-friendly syntax and expressive code.

Secret: Ruby feels natural to write, almost like you’re expressing thoughts in plain English.

Example:

5.times { puts "I love Ruby!" }

2. Everything is an Object

In Ruby, everything is treated as an object—even basic data types like numbers and booleans. This approach provides incredible consistency and flexibility.

Secret: Because everything is an object, you can call methods on anything, enabling elegant and readable code.

Example:

puts 5.class  # Output: Integer
puts "Ruby".upcase  # Output: RUBY

3. Convention Over Configuration

Ruby, particularly with frameworks like Rails, emphasizes convention over configuration. This means developers don’t have to waste time writing boilerplate code or specifying repetitive configurations.

Secret: Ruby’s defaults let you focus on solving problems, not wrestling with setup.


4. Dynamic and Flexible

Ruby is dynamically typed and highly flexible, allowing you to modify or extend core classes, define methods on the fly, and create highly customizable solutions.

Secret: You can adapt Ruby to fit your needs, even redefining built-in behavior (use with care!).

Example:

class String
  def shout
    self.upcase + "!!!"
  end
end

puts "ruby".shout  # Output: RUBY!!!

5. Readability and Beauty

Matz emphasized that code should be beautiful and readable, almost like poetry. Ruby’s syntax encourages clear, concise code that avoids clutter.

Secret: Writing Ruby code often feels like crafting art, not just solving a problem.

Example:

users = ["Alice", "Bob", "Charlie"]
users.each { |user| puts "Hello, #{user}!" }

6. Powerful Built-In Tools

Ruby comes with a rich standard library and built-in tools like blocks, Procs, and lambdas, which make it easy to implement higher-order programming.

Secret: Ruby gives you powerful abstractions for working with data and control flow.

Example:

def repeat(n, &block)
  n.times { block.call }
end

repeat(3) { puts "Ruby is awesome!" }

7. Community and Ecosystem

Ruby’s community is known for being friendly and supportive. The language also boasts a vast ecosystem of gems (libraries) and frameworks, particularly Ruby on Rails.

Secret: The Ruby community shares the philosophy of joy and productivity, offering tools and resources that simplify development.


8. Balancing Productivity and Power

Ruby may not be the fastest language in terms of raw performance, but its power lies in how much it helps developers get things done quickly and correctly. For many tasks, developer time is far more valuable than machine time.

Secret: Ruby optimizes for developer productivity, making it perfect for startups and teams that need to move fast.


9. Inspired by the Best Languages

Ruby combines the best features of several programming languages:

  • Perl for text processing.
  • Smalltalk for object orientation.
  • Lisp for its flexibility.
  • Python for readability.

Secret: Ruby is a language born from Matz cherry-picking the most enjoyable aspects of other languages.


10. Open to Everyone

Ruby’s accessibility makes it a great language for beginners, while its depth and flexibility appeal to experienced developers building complex systems.

Secret: Ruby is approachable for newcomers but powerful enough for experts.


In Summary: The Real Secret of Ruby

The true secret of Ruby is its focus on joy and creativity. It’s a language that doesn’t just help you write code—it makes you love writing code. Whether you’re a beginner learning to program or an expert building a complex application, Ruby empowers you to express your ideas beautifully and efficiently.

Would you like to explore one of these points further?

The post Top 10 secrets of Ruby appeared first on Th?nk And Grow.

]]>
What is Ruby’s Global Interpreter Lock (GIL) and How to Overcome Its Limitations? https://blog.thnkandgrow.com/what-is-rubys-global-interpreter-lock-gil-and-how-to-overcome-its-limitations/ Sun, 17 Nov 2024 00:32:00 +0000 https://blog.thnkandgrow.com/?p=1850 The Global Interpreter Lock (GIL) is a mechanism used in certain programming languages, including MRI (Matz’s Ruby Interpreter, the most widely used Ruby implementation), to synchronize access to the interpreter’s internal structures. It ensures that only one thread executes Ruby code at a time, even on multi-core processors. Why Does the GIL Exist? The GIL […]

The post What is Ruby’s Global Interpreter Lock (GIL) and How to Overcome Its Limitations? appeared first on Th?nk And Grow.

]]>
The Global Interpreter Lock (GIL) is a mechanism used in certain programming languages, including MRI (Matz’s Ruby Interpreter, the most widely used Ruby implementation), to synchronize access to the interpreter’s internal structures. It ensures that only one thread executes Ruby code at a time, even on multi-core processors.


Why Does the GIL Exist?

The GIL simplifies the implementation of the interpreter by avoiding thread safety issues. Ruby’s C-based implementation uses shared data structures, and the GIL ensures that threads don’t access or modify these shared structures concurrently, which could lead to unpredictable behavior or crashes.


How the GIL Works

  1. At any given time, only one thread is allowed to execute Ruby code.
  2. Other threads must wait for the current thread to release the GIL, even if running on a multi-core CPU.
  3. However, threads waiting for I/O (e.g., file reading or network requests) can release the GIL, allowing other threads to execute Ruby code in the meantime.
how thread works

Implications of the GIL

  1. Limits True Parallelism:
  • On a multi-core CPU, the GIL prevents Ruby threads from running Ruby code in parallel on separate cores.
  • As a result, Ruby’s threads are better suited for I/O-bound tasks (e.g., waiting for network responses) than for CPU-bound tasks.
  1. Multi-Process Advantage:
  • To utilize multiple CPU cores, Ruby developers often use processes instead of threads. Processes don’t share memory and aren’t affected by the GIL, allowing true parallelism.
  1. I/O-Bound Tasks Work Well:
  • The GIL doesn’t block non-Ruby operations (e.g., I/O operations, database queries). In such cases, threads can achieve concurrency because they release the GIL while waiting.

Which Ruby Versions/Implementations Have a GIL?

  • MRI Ruby: Has a GIL, so threads are limited in their ability to run in parallel.
  • JRuby: No GIL. It uses the JVM (Java Virtual Machine), allowing true multi-threading.
  • TruffleRuby: No GIL. Designed for better concurrency and performance.
  • Rubinius: No GIL. It provides native threads without this limitation.

Example: GIL in Action

require 'benchmark'

def cpu_bound_task
  1_000_000.times { |i| i * i }
end

threads = []
time = Benchmark.realtime do
  4.times do
    threads << Thread.new { cpu_bound_task }
  end
  threads.each(&:join)
end

puts "Time taken: #{time} seconds"

Result on MRI Ruby:
Even with multiple threads, the time taken is similar to running the task sequentially because only one thread runs Ruby code at a time.


When Is the GIL Not a Problem?

  • I/O-bound tasks (e.g., network requests, file reads/writes).
  • Applications that rely on external libraries or native extensions (e.g., C code, which is GIL-independent).

Conclusion

The GIL is both a blessing and a limitation for Ruby developers:

  • It makes Ruby’s interpreter simpler and safer but restricts true multi-threading.
  • For tasks that need true parallelism, use multiple processes or an alternative Ruby implementation like JRuby or TruffleRuby.
    Understanding the GIL helps you design efficient Ruby applications by choosing the right concurrency approach for your needs.

The post What is Ruby’s Global Interpreter Lock (GIL) and How to Overcome Its Limitations? appeared first on Th?nk And Grow.

]]>
Uncover Ruby’s Hidden Operators and Symbols: Advanced Techniques for Ruby Developers https://blog.thnkandgrow.com/uncover-rubys-hidden-operators-and-symbols-advanced-techniques-for-ruby-developers/ Thu, 14 Nov 2024 05:01:00 +0000 https://blog.thnkandgrow.com/?p=1812 Introduction Ruby is a language that shines because of its expressive syntax, which often makes code cleaner and more readable. Many Rails developers are familiar with basic operators and symbols, but there are a few “hidden gems” that can add serious power and flexibility to your code. This post will cover some advanced operators and […]

The post Uncover Ruby’s Hidden Operators and Symbols: Advanced Techniques for Ruby Developers appeared first on Th?nk And Grow.

]]>
Introduction

Ruby is a language that shines because of its expressive syntax, which often makes code cleaner and more readable. Many Rails developers are familiar with basic operators and symbols, but there are a few “hidden gems” that can add serious power and flexibility to your code. This post will cover some advanced operators and symbols in Ruby—tools that allow you to write cleaner, more versatile, and more elegant code in your Rails applications.


1. Safe Navigation Operator (&.)

What It Does

The safe navigation operator (&.) is a lifesaver for handling potentially nil values. It allows you to call a method on an object only if the object is not nil, helping you avoid NoMethodError exceptions.

Use Case: Avoiding nil Errors in ActiveRecord Associations

In Rails, it’s common to chain associations that might be nil. For example, if user.profile might be nil, calling user.profile.location can raise an error. The safe navigation operator handles this smoothly:

location = user.profile&.location

If profile is nil, &. prevents the method from being called, returning nil instead of raising an error.


2. Memoization Operator (||=)

What It Does

The ||= operator is a shorthand for memoization. It assigns a value to a variable only if that variable is currently nil or false, caching expensive operations for future use.

Use Case: Caching Expensive Queries

When you have a query you don’t want to run multiple times, ||= can store the result the first time it’s called.

def recent_orders
  @recent_orders ||= Order.where(user_id: id).order(created_at: :desc).limit(5)
end

Here, @recent_orders is only set once, preventing repeated database queries and improving performance.


3. Spaceship Operator (<=>)

What It Does

The spaceship operator (<=>) returns -1, 0, or 1, indicating whether the left operand is less than, equal to, or greater than the right operand. It’s especially useful for custom sorting.

Use Case: Case-Insensitive Sorting

users.sort { |a, b| a.last_name.downcase <=> b.last_name.downcase }

This operator makes it easy to define custom comparison logic, useful when sorting complex objects by multiple attributes.


4. Pattern Matching Operator (in)

What It Does

The pattern matching operator (in), introduced in Ruby 2.7, destructures data based on defined patterns. It’s handy for working with nested data structures like JSON responses.

Use Case: Parsing API Responses

data = { user: { name: "Alice", address: { city: "Wonderland" } } }

case data
in { user: { name: name, address: { city: city } } }
  puts "Name: #{name}, City: #{city}"
else
  puts "Invalid data format"
end

Pattern matching provides a concise way to handle nested data, making it easier to extract information from complex structures.


5. Flip-Flop Operator (.. in Conditionals)

What It Does

The flip-flop operator creates a conditional range, evaluating as true between two specified conditions. It’s useful for processing data between two markers.

Use Case: Processing Log Files

File.foreach("log.txt") do |line|
  puts line if line =~ /START/..line =~ /END/
end

This operator lets you capture lines in a file between START and END markers, making it useful for filtering log data or configuration files.


6. Tilde Operator (~) with Regular Expressions

What It Does

The tilde operator (~) checks if a string matches a regex, returning a truthy or falsy value.

Use Case: Validating Data Formats

def valid_email?(email)
  !!~email.match(/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i)
end

This operator simplifies regex checks, making it easier to implement basic format validation within conditions.


7. Defined? Operator

What It Does

The defined? operator checks if a variable, method, or constant is defined. It can prevent errors when accessing variables in dynamically loaded contexts.

Use Case: Conditional Definitions in Views

<%= user.name if defined?(user) %>

This allows for conditional rendering in views, preventing undefined method errors when variables may or may not be present.


8. Splat (*) and Double Splat (**) Operators

The * (Splat) Operator

The splat operator (*) captures multiple arguments into an array, allowing methods to accept any number of arguments.

Use Case: Flexible Query Parameters

class User < ApplicationRecord
  scope :by_status, ->(*statuses) { where(status: statuses) }
end

User.by_status('active', 'pending', 'suspended')

The *statuses captures all arguments, making the scope adaptable for any number of statuses.

The ** (Double Splat) Operator

The double splat operator (**) captures keyword arguments into a hash, allowing flexible options for method configurations.

Use Case: Dynamic Query Filters

def find_users(**options)
  User.where(options)
end

find_users(age: 25, location: 'New York', status: 'active')

Using **options allows you to handle varying keyword arguments, which is particularly useful for filters in Rails methods.

Combining * and **

Using both * and ** in a method gives you maximum flexibility for handling both positional and keyword arguments.

class UserService
  def find_users(*ids, **filters)
    users = User.where(id: ids)
    users = users.where(filters) unless filters.empty?
    users
  end
end

UserService.new.find_users(1, 2, 3, status: 'active', age: 30)

This method can handle both an array of IDs and a hash of filters, making it adaptable to a variety of inputs.


Conclusion

The special operators and symbols in Ruby can take your Rails development skills to a new level. From safe navigation to pattern matching, splats, and double splats, these tools make your code more flexible, readable, and powerful. By incorporating these techniques, you’ll be able to handle complex scenarios with elegance and simplicity—making your Rails applications not only better but also more enjoyable to write.


Takeaway: These operators and symbols may not be as widely used, but they can be game-changers in Ruby and Rails code. Give them a try, and you might be surprised at how much cleaner and more flexible your code becomes!

The post Uncover Ruby’s Hidden Operators and Symbols: Advanced Techniques for Ruby Developers appeared first on Th?nk And Grow.

]]>
Mastering Real-Time Scalability: Redis Solutions for Session Management and Load Balancing in High-Traffic Apps https://blog.thnkandgrow.com/real-time-redis-session-load-balancing/ Sun, 10 Nov 2024 17:19:54 +0000 https://blog.thnkandgrow.com/?p=1687 Building a Load-Balanced Uber-like Application with Redis When building an application with similar requirements to Uber, seamless session management and real-time updates are essential. Redis can significantly enhance scalability and performance, handling both HTTP session persistence and WebSocket connections across multiple servers. Solution 1: Session Management via Redis (Redis as a Session Store) This approach […]

The post Mastering Real-Time Scalability: Redis Solutions for Session Management and Load Balancing in High-Traffic Apps appeared first on Th?nk And Grow.

]]>
Building a Load-Balanced Uber-like Application with Redis

When building an application with similar requirements to Uber, seamless session management and real-time updates are essential. Redis can significantly enhance scalability and performance, handling both HTTP session persistence and WebSocket connections across multiple servers.

overview

Solution 1: Session Management via Redis (Redis as a Session Store)

This approach is beneficial for handling user logins, authentication states, and HTTP request data persistence across multiple server instances. Redis stores session data, ensuring that all instances can access consistent session information.

Solution-1: Mechanism

Setup Steps

  1. Initialize a NestJS Project
nest new uber-clone
cd uber-clone
npm install express-session connect-redis redis
  1. Set up Redis and Connect Redis to Session

Install and start a Redis server, then configure it within your NestJS application.

// src/main.ts
import * as session from 'express-session';
import * as connectRedis from 'connect-redis';
import { createClient } from 'redis';

const RedisStore = connectRedis(session);
const redisClient = createClient();

app.use(
  session({
    store: new RedisStore({ client: redisClient }),
    secret: 'superSecretKey',
    resave: false,
    saveUninitialized: false,
  }),
);
  1. Use the Session in Controllers

Access the session data from controllers to store user data (e.g., ride details or location).

// src/app.controller.ts
@Get('location')
getUserLocation(@Session() session: any) {
  return session.userLocation;
}

@Post('location')
updateUserLocation(@Session() session: any, @Body() location: LocationDto) {
  session.userLocation = location;
}
  1. Test the Session Persistence

Start multiple instances to test if user data is maintained across instances. Redis will ensure each instance has access to the session data, regardless of the specific server handling the request.

Advantages of Redis as a Session Store

  • Reliable HTTP session persistence across servers.
  • Ideal for storing authentication and user-specific data in a centralized store.
  • Simple setup for RESTful applications and user-based session data.
Solution-1: Advantages

Solution 2: Real-Time WebSocket Management via Redis Adapter

For applications like Uber with real-time updates (ride status, driver location), maintaining consistent WebSocket connections across instances is critical. The Redis adapter allows WebSocket events to be shared across instances, making it ideal for high-traffic, real-time updates.

Solution-1: Mechanism

Setup Steps

  1. Install Required Packages
npm install @nestjs/websockets @nestjs/platform-socket.io socket.io-redis
  1. Configure Redis Adapter

Use Redis as a WebSocket adapter, allowing all instances to receive and process WebSocket events in real-time.

// src/main.ts
import { IoAdapter } from '@nestjs/platform-socket.io';
import { createAdapter } from 'socket.io-redis';

const redisAdapter = createAdapter({ host: 'localhost', port: 6379 });
const app = await NestFactory.create(AppModule);
app.useWebSocketAdapter(new IoAdapter(app).use(redisAdapter));
  1. Implement WebSocket Events in Controllers

Create WebSocket endpoints that send updates to all clients connected to any instance.

// src/rides.gateway.ts
import { WebSocketGateway, WebSocketServer, SubscribeMessage } from '@nestjs/websockets';

@WebSocketGateway()
export class RidesGateway {
  @WebSocketServer() server;

  @SubscribeMessage('locationUpdate')
  handleLocationUpdate(client: any, payload: any): void {
    this.server.emit('locationUpdate', payload); // Broadcast update to all clients
  }
}
  1. Test Real-Time Updates Across Multiple Instances

Run multiple instances and test if location updates (e.g., driver’s real-time location) are synced across all connected clients. Redis ensures WebSocket events are shared across instances, keeping users updated regardless of the instance handling their connection.

Advantages of Redis Adapter for WebSocket Management

  • Ensures real-time updates across all client instances.
  • Essential for real-time features, ensuring a unified event stream.
  • Ideal for high-traffic applications that require live updates, such as ride-sharing.
Solution-2: Advantages

Comparison of Redis Session vs. Redis Adapter

FeatureRedis SessionRedis Adapter
Best ForHTTP session management, authenticationReal-time updates, WebSocket management
Use CasePersistent login, user data storageLocation updates, ride status
Setup ComplexityLowModerate
Ideal ApplicationAny RESTful or HTTP-based applicationsReal-time, event-driven applications
Comparison of Redis Session vs. Redis Adapter

Conclusion

When building a scalable, Uber-like application, both Redis session management and Redis adapter for WebSocket events offer unique benefits. Choose Redis sessions to maintain HTTP data consistency, or Redis adapter for managing real-time events across instances. Together, they create a scalable, responsive architecture that meets the demands of modern applications.

Conclusion

This architecture approach offers scalability and performance, ensuring users have a seamless experience regardless of the number of users connected. For applications like Uber, which rely on both user sessions and real-time updates, integrating Redis in these ways can provide a robust solution.

The post Mastering Real-Time Scalability: Redis Solutions for Session Management and Load Balancing in High-Traffic Apps appeared first on Th?nk And Grow.

]]>
Method Lookup in Ruby: How Ruby Finds Methods https://blog.thnkandgrow.com/method-lookup-in-ruby-how-ruby-finds-methods/ Wed, 06 Nov 2024 01:35:33 +0000 https://blog.thnkandgrow.com/?p=1575 When calling a method on an object in Ruby, the language searches for that method across a hierarchy of classes and modules. This lookup process ensures that Ruby finds the correct method to execute, even if it’s defined in a superclass, module, or as a singleton. In this blog post, we’ll dive deep into Ruby’s […]

The post Method Lookup in Ruby: How Ruby Finds Methods appeared first on Th?nk And Grow.

]]>
When calling a method on an object in Ruby, the language searches for that method across a hierarchy of classes and modules. This lookup process ensures that Ruby finds the correct method to execute, even if it’s defined in a superclass, module, or as a singleton. In this blog post, we’ll dive deep into Ruby’s method lookup process, covering essential concepts with examples to help you understand how it works.


Table of Contents

  1. Introduction to Method Lookup
  2. Singleton Classes and Their Role in Method Lookup
  3. Class and Module Lookup
  4. The Role of method_missing
  5. Putting It All Together with Detailed Examples

1. Introduction to Method Lookup in Ruby

In Ruby, method lookup is the process of finding the correct method to execute when you call a method on an object. Ruby’s lookup path is known as the method lookup chain. When you call object.method_name, Ruby checks the following locations in this order:

  1. Singleton class (if the object has one)
  2. Class of the object
  3. Modules included in the class (in reverse order of inclusion)
  4. Superclass and its modules
  5. Object and Kernel modules
  6. BasicObject

If Ruby doesn’t find the method after exhausting the lookup chain, it calls method_missing.


2. Singleton Classes and Their Role in Method Lookup

A singleton class (or eigenclass) allows defining methods on a single instance of a class. Ruby checks the singleton class first, which lets you override methods or define new ones for individual objects.

Example of Singleton Method Lookup

class Animal
  def speak
    "I am an animal"
  end
end

dog = Animal.new

# Adding a singleton method to `dog`
def dog.speak
  "I am a dog"
end

puts dog.speak      # => "I am a dog"
puts Animal.new.speak # => "I am an animal"

When dog.speak is called, Ruby checks dog‘s singleton class and finds the speak method there, so it doesn’t proceed to the Animal class.


3. Class and Module Lookup

If no method is found in the singleton class, Ruby continues looking in the object’s class and any modules included in that class. Modules are included in reverse order of inclusion, so the last included module is checked first.

Example of Module Lookup

module Walkable
  def move
    "I can walk"
  end
end

module Swimmable
  def move
    "I can swim"
  end
end

class Animal
  include Walkable
  include Swimmable
end

dog = Animal.new
puts dog.move # => "I can swim"

In this case, the Swimmable module is checked before Walkable because it was included last. Thus, dog.move calls the move method from Swimmable.


4. The Role of Superclass and Kernel

After the object’s class and its included modules, Ruby moves up the inheritance chain. Ruby keeps checking the superclass and any modules included in it until it reaches the Object class, which includes the Kernel module for commonly used methods.

Example of Superclass Lookup

class Animal
  def eat
    "Eating food"
  end
end

class Dog < Animal
end

dog = Dog.new
puts dog.eat # => "Eating food"

Since eat is defined in the superclass Animal, dog.eat finds and uses this method, even though it’s not defined in Dog.


5. method_missing: Handling Unfound Methods

If the method isn’t found in any of the checked locations, Ruby calls the method_missing method, which can be customized to handle unknown methods.

Example of method_missing

class Animal
  def method_missing(method_name, *args)
    "#{method_name} is not defined"
  end
end

dog = Animal.new
puts dog.run # => "run is not defined"

Here, run isn’t defined anywhere in Animal or its ancestors, so method_missing is called and handles the output.


6. Detailed Examples of Method Lookup in Action

Let’s see an extended example that combines all these elements to illustrate the complete lookup process.

Comprehensive Example

module Swimmable
  def move
    "I can swim"
  end
end

module Walkable
  def move
    "I can walk"
  end
end

class Animal
  include Walkable
end

class Dog < Animal
  include Swimmable

  def speak
    "Bark!"
  end
end

dog = Dog.new

# Singleton method definition
def dog.speak
  "I am a unique dog"
end

puts dog.speak      # => "I am a unique dog" (singleton class)
puts Dog.new.speak  # => "Bark!" (Dog class)

puts dog.move       # => "I can swim" (Swimmable module)

In this example:

  1. dog.speak: Ruby checks the singleton class first and finds speak.
  2. Dog.new.speak: Since there’s no singleton method, Ruby checks Dog, where it finds speak.
  3. dog.move: Ruby finds move in the Swimmable module, included last in Dog.

This order preserves modularity and lets developers create flexible, maintainable code by layering methods through modules and superclasses.


Conclusion

Understanding method lookup in Ruby is essential for writing effective, modular, and efficient code. This lookup chain allows Ruby to provide powerful features, such as singleton methods and module inclusion, which let you customize behavior at various levels in the inheritance hierarchy. Whether working on small applications or large codebases, knowing how Ruby finds methods can help avoid pitfalls and improve debugging efficiency.

The post Method Lookup in Ruby: How Ruby Finds Methods appeared first on Th?nk And Grow.

]]>