Notes / ruby
- Notes on Rebuilding Rails Currently reading Rebuilding Rails by Noah Gibbs. Notes: Chapter 3 Sometimes, Noah writes methods in the context of a module, sometimes in the context of a class. Why? Modules are collections of methods and constants. They cannot generate instances. Classes may generate instances (objects), and have per-instance state (instance variables). Source Checking rails/active_support_dependencies/autoload.rb and I see this @_at_path. What is the reason for this @_? So, @_instance_var has no special meaning. Rails internally uses it to distinguish private/protected variables that other should not modify/access. source bundler: failed to load command: rackup Couldn't find handler for: puma, thin, falcon, webrick. (LoadError)
- StringScanner Currently reading Rebuilding Rails by Noah Gibbs. At some point, he writes about checking out Active Support for some pointers on metaprogramming. Currently felt into a rabbit hole on the duration part of the lib. Anyways. Here’s a nifty class in Ruby that facilitates some scanning on strings. StringScanner provides for lexical scanning operations on a String. source Usage: string = StringScanner.new("bob") => #<StringScanner 0/3 @ "bob"> [9] pry(main)> string.eos? => false [10] pry(main)> string.pos => 0 [12] pry(main)> string.peek(5) => "bob" [14] pry(main)> string.getch => "b" [15] pry(main)> string.pos => 1 [16] pry(main)> string.reset => #<StringScanner 0/3 @ "bob">