Skip to content

Instantly share code, notes, and snippets.

@theycallmeS
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save theycallmeS/e48fa90c1f599abcd211 to your computer and use it in GitHub Desktop.

Select an option

Save theycallmeS/e48fa90c1f599abcd211 to your computer and use it in GitHub Desktop.

Revisions

  1. theycallmeS revised this gist Dec 23, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion class_eval.md
    Original file line number Diff line number Diff line change
    @@ -15,4 +15,6 @@ class_eval <<-"end_eval", __FILE__, __LINE__
    end_eval
    ```

    [`class_eval`](http://www.ruby-doc.org/core-2.1.5/Module.html#method-i-class_eval) (as well as `module_eval` and some other methods) actually takes blocks _or strings_ for evaluation, so instead of passing a block, we pass everything as a [here-document](http://en.wikipedia.org/wiki/Here_document#Ruby) string, and add two additional params for filename and line in that file. So when exception hits the fan, it will be trivial to locate.
    [`class_eval`](http://www.ruby-doc.org/core-2.1.5/Module.html#method-i-class_eval) (as well as `module_eval` and some other methods) actually takes blocks _or strings_ for evaluation, so instead of passing a block, we pass everything as a [here-document](http://en.wikipedia.org/wiki/Here_document#Ruby) string, and add two additional params for filename and line in that file.

    When exception hits the fan, it will be trivial to locate.
  2. theycallmeS revised this gist Dec 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion class_eval.md
    Original file line number Diff line number Diff line change
    @@ -15,4 +15,4 @@ class_eval <<-"end_eval", __FILE__, __LINE__
    end_eval
    ```

    [`class_eval`](http://www.ruby-doc.org/core-2.1.5/Module.html#method-i-class_eval) (as well as `module_eval` and some other methods) actually takes blocks _or strings_ for evaluation, so instead of passing a block, we pass everything as a [here-document](http://en.wikipedia.org/wiki/Here_document#Ruby), and add two additional params for filename and line in that file. So when exception hits the fan, it will be trivial to locate.
    [`class_eval`](http://www.ruby-doc.org/core-2.1.5/Module.html#method-i-class_eval) (as well as `module_eval` and some other methods) actually takes blocks _or strings_ for evaluation, so instead of passing a block, we pass everything as a [here-document](http://en.wikipedia.org/wiki/Here_document#Ruby) string, and add two additional params for filename and line in that file. So when exception hits the fan, it will be trivial to locate.
  3. theycallmeS created this gist Dec 23, 2014.
    18 changes: 18 additions & 0 deletions class_eval.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    Use here_document with `class_eval` to simplify debugging:

    ```ruby
    class_eval <<-"end_eval", __FILE__, __LINE__
    def #{block_accessor}(*args, &block)
    unless args.empty? && block.nil?
    args.push block if block_given?
    @#{block_accessor} = [args].flatten
    end
    @#{block_accessor}
    end
    end_eval
    ```

    [`class_eval`](http://www.ruby-doc.org/core-2.1.5/Module.html#method-i-class_eval) (as well as `module_eval` and some other methods) actually takes blocks _or strings_ for evaluation, so instead of passing a block, we pass everything as a [here-document](http://en.wikipedia.org/wiki/Here_document#Ruby), and add two additional params for filename and line in that file. So when exception hits the fan, it will be trivial to locate.