How do you declare a Rake task that depends on a parameterized task?

Args are passed down through the call stack. You just need to make sure your top-level task captures all the arguments all of the dependencies require. In your case you’ll want to put first_name and last_name on the send_letter task. Here is an example that shows named arguments defined elsewhere flowing into the dependency (even … Read more

Ruby – determining method origins?

Object#method returns a Method object giving meta-data about a given method. For example: > [].method(:length).inspect => “#<Method: Array#length>” > [].method(:max).inspect => “#<Method: Array(Enumerable)#max>” In Ruby 1.8.7 and later, you can use Method#owner to determine the class or module that defined the method. To get a list of all the methods with the name of the … Read more

Ruby: What does $1 mean?

According to Avdi Grimm from RubyTapas $1 is a global variable which can be used in later code: if “foobar” =~ /foo(.*)/ then puts “The matching word was #{$1}” end Output: “The matching word was bar” In short, $1, $2, $… are the global-variables used by some of the ruby library functions specially concerning REGEX … Read more

Backslashes in single quoted strings vs. double quoted strings

Double-quoted strings support the full range of escape sequences, as shown below: \a Bell/alert (0x07) \b Backspace (0x08) \e Escape (0x1b) \f Formford (0x0c) \n Newline (0x0a) \r Return (0x0d) \s Space (0x20) \t Tab (0x09) \v Vertical tab (0x0b) For single-quoted strings, two consecutive backslashes are replaced by a single backslash, and a backslash … Read more