Skip to content

Instantly share code, notes, and snippets.

@codeimpossible
Created August 29, 2012 18:05
Show Gist options
  • Save codeimpossible/3516357 to your computer and use it in GitHub Desktop.
Save codeimpossible/3516357 to your computer and use it in GitHub Desktop.
<< evaluation in Ruby
def find(since=nil, til=nil)
@where << since ? " AND C.time >= #{since}" : ""
@where << til ? " AND C.time <= #{til}" : ""
find_by_sql make_sql #assume this generates SQL statement using @where and some other stuff...
end
# Question 1: Why does the above fail with this error:
# TypeError: can't convert nil into String
# from (irb):3:in `<<'
# from (irb):3
#
# Question 2: How can we make this pass with the fewest code changes?
# Question 3: Is there another syntax we could use that would do the same thing?
@codeimpossible
Copy link
Author

The comments are bit light to read on a white background. Here they are:

Question 1: Why does the above fail with this error:

TypeError: can't convert nil into String
    from (irb):3:in `<<'
    from (irb):3

Question 2: How can we make this pass with the fewest code changes?
Question 3: Is there another syntax we could use that would do the same thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment