api: "YAML JSON TOON Database"
version: "1.0.0"
format: "json"
dataset:
  id: 50
  slug: "ruby-language-essentials"
  title: "Ruby Language Essentials"
  description: "Core Ruby programming concepts: blocks, procs, lambdas, metaprogramming, gems, Rails conventions, and Ruby idioms."
  category: "Programming Languages"
  category_slug: "programming-languages"
  tags: "ruby,rails,blocks,procs,lambdas,metaprogramming,gems,idioms"
  view_count: 0
  created_at: 1778695229
  updated_at: 1778695229
data:
  concepts:
    - name: "Blocks"
      type: "Anonymous code chunks"
      syntax: "{ |args| code } or do...end"
      description: "Chunks of code passed to methods, fundamental to Ruby iteration and DSLs"
      example: "5.times { puts 'Hello' }"
    - name: "Procs"
      type: "Stored blocks"
      syntax: "Proc.new { |args| code }"
      description: "Blocks converted to objects, can be stored in variables and passed around"
      example: "my_proc = Proc.new { |x| x * 2 }; my_proc.call(5)"
    - name: "Lambdas"
      type: "Strict procs"
      syntax: "->(args) { code } or lambda { |args| code }"
      description: "Like procs but with strict arity checking and return semantics (like methods)"
      example: "my_lambda = ->(x) { x + 1 }; my_lambda.call(3)"
    - name: "Metaprogramming"
      type: "Runtime code generation"
      syntax: "define_method, method_missing, send, class_eval"
      description: "Writing code that writes code: dynamic method definition, method interception, eval families"
      example: "define_method(:greet) { |name| puts \"Hello, #{name}\" }"
    - name: "Mixins (Modules)"
      type: "Shared behavior"
      syntax: "module MyModule; def method; end; end; class Foo; include MyModule; end"
      description: "Share methods across classes without inheritance, avoid multiple inheritance"
      example: "module Comparable; def <(other); self <=> other == -1; end; end"
    - name: "Enumerable"
      type: "Collection protocol"
      syntax: "include Enumerable; def each; end"
      description: "Module providing iteration methods (map, select, reduce) to any class implementing #each"
      example: "class MyCollection; include Enumerable; def each(&block); items.each(&block); end; end"
    - name: "Singleton Methods"
      type: "Per-object methods"
      syntax: "def obj.method; end or obj.define_singleton_method(:m) { }"
      description: "Methods defined on a single object instance, not its class"
      example: "str = 'hello'; def str.shout; self.upcase + '!'; end; str.shout # => 'HELLO!'"
    - name: "Method Missing"
      type: "Dynamic dispatch"
      syntax: "def method_missing(name, *args, &block); end"
      description: "Intercept calls to undefined methods for DSLs, proxies, and dynamic behavior"
      example: "def method_missing(name); name.to_s.reverse; end; obj.hello #=> 'olleh'"
