Given an otherwise empty Rails app with the following two models:
# app/models/cities/massachusetts/boston.rb
class Cities::Massachusetts::Boston
def self.refer_to_denver
begin
Colorado::DenverGiven an otherwise empty Rails app with the following two models:
# app/models/cities/massachusetts/boston.rb
class Cities::Massachusetts::Boston
def self.refer_to_denver
begin
Colorado::DenverI'd always assumed that alias_method(new, existing) was equivalent to something like the following (plus support for passing arguments and a block along):
def new
existing
endBut no, apparently it really does just give you another name with which you can refer to the same method body. Thus:
I do not like the way Ruby does its constant name resolution.
Suppose somewhere in your codebase you define a module Parent:
module Parent
FOO = "foo"
endAnd some other place, you add a method onto a module inside Parent called Child:
In my codebase, I've got something like the following, where Foo, Bar, and Baz are classes:
case o
when Foo then process!
when Bar then trash!
when Baz then flag!
else raise ArgumentError, "unexpected type #{o.class}"
endBackground:
'foo'.frozen? is false.Question: {'foo' => true}.keys.first.frozen?
Answer: true
Okay. I can totally see why you don't want hash keys to be mutable. That's completely sensible.
Question: {[] => true}.keys.first.frozen?
I wanted to output a list of single-line strings, each item separated by a newline. I couldn't find a way to do that without combining them all into a single string. Fine.
Reasonable attempt:
osascript -e '
set myList to {"foo", "bar", "baz"}
set myString to ""
repeat with myItem in myList
set myString to myString & myItem & return