Ruby
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Methods and Blocks
-
Section 4: Object-Oriented Ruby
-
Section 5: Metaprogramming
-
Section 6: Working with Data and Files
-
Section 7: Ruby Frameworks Overview
-
Section 8: Ecosystem and Testing
-
Section 9: Practical Projects
-
Section 10: Interview Practice
-
Section 11: Data Structures and Algorithms in Ruby
-
Section 12: More Practice Exercises
-
Section 13: Enumerable and Functional Style
-
Section 14: More OOP Practice
-
Section 15: More Testing
-
Section 16: Enumerable and Comparable Modules In Depth
-
Section 17: Ruby Standard Library: Core Utilities
-
Section 18: Ruby Standard Library: Data and Security
-
Section 19: Ruby Standard Library: CLI and Text
-
Section 20: Ruby Networking
-
Section 21: Ruby on Rails Deep Dive
-
Section 22: Ruby Metaprogramming Deep Dive
-
Section 23: Ruby Design Patterns
-
Section 24: Ruby Concurrency
-
Section 25: Ruby Testing Deep Dive
-
Section 26: Ruby Gems and Packaging
-
Section 27: Ruby Performance
-
Section 28: More Practice Exercises
-
Section 29: More Interview Practice
-
Section 30: Rails API Development
-
Section 31: Rails Authentication and Authorization
-
Section 32: Rails Testing Deep Dive
-
Section 33: Rails Performance
-
Section 34: Rails Deployment
-
Section 35: Sinatra and Lightweight Ruby Web Apps
-
Section 36: More Ruby Language Deep Dive
-
Section 37: Ruby 3.x Modern Features
-
Section 38: More Data Structures in Ruby
-
Section 39: More Practical Projects
-
Section 40: Ruby Ecosystem Tools
-
Section 41: More Practice and Review
-
Section 42: Final Practice and Mastery
-
Section 43: Ruby Interview Deep Dive
-
Section 44: Ruby Background Processing Deep Dive
-
Section 45: Ruby GraphQL
-
Section 46: Ruby Object Model Deep Dive
-
Section 47: Ruby Hanami Framework Overview
-
Section 48: Ruby gRPC and Protocol Buffers
-
Section 49: Ruby Data Processing
-
Section 50: Ruby Search Integration
-
Section 51: Ruby File Upload and Media
-
Section 52: Ruby Email and Notifications
-
Section 53: Ruby Admin Panels
-
Section 54: Ruby Feature Flags and Experimentation
-
Section 55: Ruby Monitoring and Observability
-
Section 56: Ruby Docker and Deployment Deep Dive
-
Section 57: Ruby Security Deep Dive
-
Section 58: More Advanced Metaprogramming
-
Section 59: More Final Projects
167: Solargraph for Language Server Support
You've probably experienced this: you're deep in a project, you call a method on an object that you know exists, but your editor is stubbornly underlining it in red or refusing to show you the documentation when you hover over it. You run the code, and it works perfectly. The "bug" isn't in your Ruby code—it's in your tooling. This is where Solargraph comes in.
class Invoice
attr_reader :client
def initialize(client)
@client = client
end
def generate_bill(amount)
# Your editor is likely flagging this as an 'undefined method'
# or giving you zero autocomplete options for .send_notification
client.send_notification("Your bill is #{amount}")
end
end
class Client
def send_notification(msg)
puts "Emailing client: #{msg}"
end
end
# This runs fine, but the IDE is blind
Invoice.new(Client.new).generate_bill(50)
The Blind Spot in Dynamic Typing
In the example above, the Invoice#generate_bill method takes a client object. Because Ruby is dynamically typed, Solargraph (the Language Server) looks at client and sees... nothing. It doesn't know if client is a Client object, a String, or a Hash. It can't look inside the Client class to find send_notification because there is no explicit link between the variable and the class.
I used to just ignore these warnings and rely on my memory, but as projects grow to thousands of lines, that's a recipe for burnout. You want your editor to be your external brain, not a source of false alarms.
Teaching Solargraph via YARD Tags
The fix isn't to change how your code runs, but to provide "hints" that Solargraph can read. Solargraph relies heavily on YARD (Yay! A Ruby Documentation tool). By adding a specific type tag to your method documentation, you bridge the gap between the dynamic nature of Ruby and the static requirements of a language server.
class Invoice
attr_reader :client
# @param client [Client] The client object handling notifications
def initialize(client)
@client = client
end
def generate_bill(amount)
# Now, when you type 'client.', Solargraph knows it's a Client object
# and will suggest .send_notification automatically.
client.send_notification("Your bill is #{amount}")
end
end
By adding @param client [Client], you're telling Solargraph: "Hey, whenever you see the variable client in this context, treat it as an instance of the Client class." The red underlines vanish, and the autocomplete starts working. It's a small investment in documentation that saves hours of jumping between files to check method names.
Fixing Missing Core Library Definitions
Sometimes, even standard Ruby methods (like those in Enumerable or BigDecimal) won't show up in your autocomplete. This usually happens because Solargraph's internal index of the Ruby core library is out of sync with the version of Ruby you're actually running.
If you find that Array#map or String#strip aren't being suggested, don't waste time debugging your config file. Instead, run this in your terminal:
solargraph download-core
This command forces Solargraph to pull down the latest signatures for the Ruby core and standard libraries. I usually run this immediately after updating my Ruby version via rbenv or rvm. It's the "turn it off and on again" of the Ruby LSP world.
📋 Practical Task
Implementing Type Hinting for a Payment Gateway Interface
You are working on a payment processing system. You have a PaymentProcessor class that accepts different gateway objects (e.g., StripeGateway, PayPalGateway). Currently, your editor cannot provide autocomplete for the process_payment method because it doesn't know which gateway is being used.
Your Task:
- Create a
StripeGatewayclass with a method calledcharge(amount). - Create a
PaymentProcessorclass with aninitializemethod that accepts agateway. - Use a YARD
@paramtag in theinitializemethod to tell Solargraph thatgatewayis an instance ofStripeGateway. - Add a method
execute(amount)toPaymentProcessorthat callsgateway.charge(amount).
Verify your solution by ensuring that when you type gateway. inside the execute method, your editor suggests the charge method.
There are no comments for now.