Last active
August 29, 2015 14:12
-
-
Save theycallmeS/e48fa90c1f599abcd211 to your computer and use it in GitHub Desktop.
Revisions
-
theycallmeS revised this gist
Dec 23, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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. When exception hits the fan, it will be trivial to locate. -
theycallmeS revised this gist
Dec 23, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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) 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. -
theycallmeS created this gist
Dec 23, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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.