Ruby Language Essentials
Core Ruby programming concepts: blocks, procs, lambdas, metaprogramming, gems, Rails conventions, and Ruby idioms.
Core Ruby programming concepts: blocks, procs, lambdas, metaprogramming, gems, Rails conventions, and Ruby idioms.
| Name | Type | Syntax | Description | Example |
|---|---|---|---|---|
| Blocks | Anonymous code chunks | { |args| code } or do...end | Chunks of code passed to methods, fundamental to Ruby iteration and DSLs | 5.times { puts 'Hello' } |
| Procs | Stored blocks | Proc.new { |args| code } | Blocks converted to objects, can be stored in variables and passed around | my_proc = Proc.new { |x| x * 2 }; my_proc.call(5) |
| Lambdas | Strict procs | ->(args) { code } or lambda { |args| code } | Like procs but with strict arity checking and return semantics (like methods) | my_lambda = ->(x) { x + 1 }; my_lambda.call(3) |
| Metaprogramming | Runtime code generation | define_method, method_missing, send, class_eval | Writing code that writes code: dynamic method definition, method interception, eval families | define_method(:greet) { |name| puts "Hello, #{name}" } |
| Mixins (Modules) | Shared behavior | module MyModule; def method; end; end; class Foo; include MyModule; end | Share methods across classes without inheritance, avoid multiple inheritance | module Comparable; def <(other); self <=> other == -1; end; end |
| Enumerable | Collection protocol | include Enumerable; def each; end | Module providing iteration methods (map, select, reduce) to any class implementing #each | class MyCollection; include Enumerable; def each(&block); items.each(&block); end; end |
| Singleton Methods | Per-object methods | def obj.method; end or obj.define_singleton_method(:m) { } | Methods defined on a single object instance, not its class | str = 'hello'; def str.shout; self.upcase + '!'; end; str.shout # => 'HELLO!' |
| Method Missing | Dynamic dispatch | def method_missing(name, *args, &block); end | Intercept calls to undefined methods for DSLs, proxies, and dynamic behavior | def method_missing(name); name.to_s.reverse; end; obj.hello #=> 'olleh' |
The static files are identical to what the API returns, but with no rate limit and no server round trip. Use the API when you want a query and a content type; use the files when you want to cache one document.
curl "https://yjtoon.com/api/dataset/ruby-language-essentials?format=toon"
const res = await fetch( "https://yjtoon.com/static-data/dataset/ruby-language-essentials.toon" ); const toon = await res.text();
Rate limit: 120 requests per minute per IP, no key and no signup. API reference →