sourcify 0.5.0 → 0.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/.gitignore +1 -0
  2. data/HISTORY.txt +5 -0
  3. data/README.rdoc +86 -3
  4. data/Rakefile +47 -15
  5. data/lib/sourcify.rb +13 -0
  6. data/lib/sourcify/common/parser/converter.rb +29 -0
  7. data/lib/sourcify/common/parser/raw_scanner/comment.rb +23 -0
  8. data/lib/sourcify/common/parser/raw_scanner/counter.rb +43 -0
  9. data/lib/sourcify/common/parser/raw_scanner/dstring.rb +60 -0
  10. data/lib/sourcify/common/parser/raw_scanner/extensions.rb +121 -0
  11. data/lib/sourcify/common/parser/raw_scanner/heredoc.rb +26 -0
  12. data/lib/sourcify/common/parser/source_code.rb +33 -0
  13. data/lib/sourcify/common/ragel/common.rl +5 -0
  14. data/lib/sourcify/common/ragel/expressions.rl +38 -0
  15. data/lib/sourcify/{proc/scanner.rl → common/ragel/machines.rl} +10 -178
  16. data/lib/sourcify/errors.rb +4 -0
  17. data/lib/sourcify/method.rb +134 -0
  18. data/lib/sourcify/method/methods.rb +3 -0
  19. data/lib/sourcify/method/methods/to_raw_source.rb +30 -0
  20. data/lib/sourcify/method/methods/to_sexp.rb +30 -0
  21. data/lib/sourcify/method/methods/to_source.rb +30 -0
  22. data/lib/sourcify/method/parser.rb +104 -0
  23. data/lib/sourcify/method/parser/converter.rb +8 -0
  24. data/lib/sourcify/method/parser/raw_scanner.rb +2494 -0
  25. data/lib/sourcify/method/parser/raw_scanner.rl +144 -0
  26. data/lib/sourcify/method/parser/raw_scanner_extensions.rb +64 -0
  27. data/lib/sourcify/method/parser/scanner.rb +48 -0
  28. data/lib/sourcify/method/parser/source_code.rb +8 -0
  29. data/lib/sourcify/proc.rb +0 -2
  30. data/lib/sourcify/proc/parser.rb +2 -5
  31. data/lib/sourcify/proc/parser/converter.rb +2 -23
  32. data/lib/sourcify/proc/{scanner.rb → parser/raw_scanner.rb} +808 -806
  33. data/lib/sourcify/proc/parser/raw_scanner.rl +149 -0
  34. data/lib/sourcify/proc/parser/raw_scanner_extensions.rb +72 -0
  35. data/lib/sourcify/proc/parser/{code_scanner.rb → scanner.rb} +9 -5
  36. data/lib/sourcify/proc/parser/source_code.rb +2 -27
  37. data/lib/sourcify/version.rb +1 -1
  38. data/spec/method/others_from_def_end_block_spec.rb +49 -0
  39. data/spec/method/others_from_define_method_spec.rb +62 -0
  40. data/spec/method/raw_scanner/block_comment_spec.rb +8 -0
  41. data/spec/method/raw_scanner/double_colons_spec.rb +8 -0
  42. data/spec/method/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
  43. data/spec/method/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
  44. data/spec/method/raw_scanner/heredoc_w_indent_spec.rb +8 -0
  45. data/spec/method/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
  46. data/spec/method/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
  47. data/spec/method/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
  48. data/spec/method/raw_scanner/per_line_comment_spec.rb +8 -0
  49. data/spec/method/raw_scanner/single_quote_str_spec.rb +8 -0
  50. data/spec/method/raw_scanner/slash_operator_spec.rb +8 -0
  51. data/spec/method/raw_scanner/spec_helper.rb +80 -0
  52. data/spec/method/spec_helper.rb +1 -0
  53. data/spec/method/to_raw_source_spec.rb +31 -0
  54. data/spec/method/to_raw_source_w_specified_strip_enclosure_spec.rb +148 -0
  55. data/spec/method/to_sexp_from_def_end_block_w_variables_spec.rb +46 -0
  56. data/spec/method/to_sexp_from_def_end_block_within_irb_spec.rb +38 -0
  57. data/spec/method/to_sexp_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +56 -0
  58. data/spec/method/to_sexp_from_define_method_w_variables_spec.rb +52 -0
  59. data/spec/method/to_sexp_from_define_method_within_irb_spec.rb +42 -0
  60. data/spec/method/to_sexp_w_specified_strip_enclosure_spec.rb +74 -0
  61. data/spec/method/to_source_from_def_end_block_w_19_extras_spec.rb +23 -0
  62. data/spec/method/to_source_from_def_end_block_w_nested_begin_spec.rb +35 -0
  63. data/spec/method/to_source_from_def_end_block_w_nested_case_spec.rb +35 -0
  64. data/spec/method/to_source_from_def_end_block_w_nested_class_spec.rb +51 -0
  65. data/spec/method/to_source_from_def_end_block_w_nested_do_end_block_spec.rb +33 -0
  66. data/spec/method/to_source_from_def_end_block_w_nested_for_spec.rb +126 -0
  67. data/spec/method/to_source_from_def_end_block_w_nested_if_spec.rb +82 -0
  68. data/spec/method/to_source_from_def_end_block_w_nested_literal_keyword_spec.rb +141 -0
  69. data/spec/method/to_source_from_def_end_block_w_nested_method_spec.rb +33 -0
  70. data/spec/method/to_source_from_def_end_block_w_nested_module_spec.rb +59 -0
  71. data/spec/method/to_source_from_def_end_block_w_nested_unless_spec.rb +82 -0
  72. data/spec/method/to_source_from_def_end_block_w_nested_until_spec.rb +179 -0
  73. data/spec/method/to_source_from_def_end_block_w_nested_while_spec.rb +179 -0
  74. data/spec/method/to_source_from_def_end_block_w_singleton_method_spec.rb +19 -0
  75. data/spec/method/to_source_from_def_end_block_within_irb_spec.rb +30 -0
  76. data/spec/method/to_source_from_def_end_w_multi_blocks_and_many_matches_spec.rb +30 -0
  77. data/spec/method/to_source_from_def_end_w_multi_blocks_and_single_match_spec.rb +36 -0
  78. data/spec/method/to_source_from_define_method_w_braced_block_spec.rb +113 -0
  79. data/spec/method/to_source_from_define_method_w_do_end_block_spec.rb +145 -0
  80. data/spec/method/to_source_from_define_method_w_multi_blocks_and_many_matches_spec.rb +56 -0
  81. data/spec/method/to_source_from_define_method_w_multi_blocks_and_single_match_spec.rb +73 -0
  82. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_many_matches_spec.rb +36 -0
  83. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_no_match_spec.rb +36 -0
  84. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_and_single_match_spec.rb +28 -0
  85. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_attached_to_spec.rb +103 -0
  86. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_many_matches_spec.rb +36 -0
  87. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_no_match_spec.rb +36 -0
  88. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_body_matcher_and_single_match_spec.rb +28 -0
  89. data/spec/method/to_source_from_define_method_w_multi_blocks_and_specified_ignore_nested_spec.rb +36 -0
  90. data/spec/method/to_source_from_define_method_within_irb_spec.rb +32 -0
  91. data/spec/method/to_source_magic_file_var_spec.rb +176 -0
  92. data/spec/method/to_source_magic_line_var_spec.rb +298 -0
  93. data/spec/method/to_source_w_specified_strip_enclosure_spec.rb +39 -0
  94. data/spec/no_method/unsupported_platform_spec.rb +26 -0
  95. data/spec/proc/raw_scanner/block_comment_spec.rb +8 -0
  96. data/spec/proc/raw_scanner/double_colons_spec.rb +8 -0
  97. data/spec/proc/raw_scanner/double_quote_str_w_interpolation_spec.rb +8 -0
  98. data/spec/proc/raw_scanner/double_quote_str_wo_interpolation_spec.rb +8 -0
  99. data/spec/proc/raw_scanner/heredoc_w_indent_spec.rb +8 -0
  100. data/spec/proc/raw_scanner/heredoc_wo_indent_spec.rb +8 -0
  101. data/spec/proc/raw_scanner/kw_block_start_alias1_spec.rb +20 -0
  102. data/spec/proc/raw_scanner/kw_block_start_alias2_spec.rb +20 -0
  103. data/spec/proc/raw_scanner/per_line_comment_spec.rb +8 -0
  104. data/spec/proc/raw_scanner/single_quote_str_spec.rb +8 -0
  105. data/spec/proc/raw_scanner/slash_operator_spec.rb +8 -0
  106. data/spec/proc/raw_scanner/spec_helper.rb +63 -0
  107. data/spec/{proc_scanner/block_comment_spec.rb → raw_scanner/block_comment_shared_spec.rb} +1 -5
  108. data/spec/{proc_scanner/double_colons_spec.rb → raw_scanner/double_colons_shared_spec.rb} +1 -5
  109. data/spec/{proc_scanner/double_quote_str_w_interpolation_spec.rb → raw_scanner/double_quote_str_w_interpolation_shared_spec.rb} +1 -5
  110. data/spec/{proc_scanner/double_quote_str_wo_interpolation_spec.rb → raw_scanner/double_quote_str_wo_interpolation_shared_spec.rb} +1 -5
  111. data/spec/raw_scanner/heredoc_w_indent_shared_spec.rb +69 -0
  112. data/spec/raw_scanner/heredoc_wo_indent_shared_spec.rb +70 -0
  113. data/spec/{proc_scanner/kw_do_alias1_spec.rb → raw_scanner/kw_block_start_alias1_shared_spec.rb} +10 -26
  114. data/spec/{proc_scanner/kw_do_alias2_spec.rb → raw_scanner/kw_block_start_alias2_shared_spec.rb} +10 -25
  115. data/spec/{proc_scanner/per_line_comment_spec.rb → raw_scanner/per_line_comment_shared_spec.rb} +1 -5
  116. data/spec/raw_scanner/shared_specs.rb +3 -0
  117. data/spec/{proc_scanner/single_quote_str_spec.rb → raw_scanner/single_quote_str_shared_spec.rb} +1 -5
  118. data/spec/{proc_scanner/slash_operator_spec.rb → raw_scanner/slash_operator_shared_spec.rb} +1 -5
  119. data/spec/run_spec.sh +7 -1
  120. data/spec/spec_helper.rb +8 -25
  121. metadata +204 -47
  122. data/.rvmrc +0 -1
  123. data/VERSION +0 -1
  124. data/lib/sourcify/proc/scanner/comment.rb +0 -21
  125. data/lib/sourcify/proc/scanner/counter.rb +0 -44
  126. data/lib/sourcify/proc/scanner/dstring.rb +0 -59
  127. data/lib/sourcify/proc/scanner/extensions.rb +0 -171
  128. data/lib/sourcify/proc/scanner/heredoc.rb +0 -24
  129. data/spec/proc_scanner/heredoc_spec.rb +0 -144
  130. data/spec/proc_scanner/spec_helper.rb +0 -33
@@ -0,0 +1,26 @@
1
+ module Sourcify
2
+ module Common
3
+ class Parser
4
+ module RawScanner #:nodoc:all
5
+ class Heredoc < Struct.new(:tag, :indented)
6
+
7
+ def <<(content)
8
+ (@contents ||= []) << content
9
+ end
10
+
11
+ def to_s
12
+ @contents.join
13
+ end
14
+
15
+ def closed?(sealer)
16
+ return false unless sealer == "\n"
17
+ parts = @contents[-1].split("\n")
18
+ return true if parts[-1] == tag
19
+ indented && parts[-1].sub(/^\s*(.*)$/,'\1') == tag
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ module Sourcify
2
+ module Common
3
+ class Parser #:nodoc:all
4
+ class SourceCode < Struct.new(:file, :line)
5
+
6
+ def line
7
+ super.pred
8
+ end
9
+
10
+ def to_s
11
+ case file
12
+ when /\(irb\)/ then from_irb_to_s
13
+ else from_file_to_s
14
+ end
15
+ end
16
+
17
+ def from_file_to_s
18
+ File.open(file, 'r') do |fh|
19
+ fh.extend(File::Tail).forward(line)
20
+ fh.readlines.join
21
+ end
22
+ end
23
+
24
+ def from_irb_to_s
25
+ # Really owe it to Florian Groß's solution @ http://rubyquiz.com/quiz38.html ...
26
+ # anyway, note that we use *line.succ* instead of *line* here.
27
+ IRB.CurrentContext.io.line(line.succ .. -1).join
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ %%{
2
+ machine common;
3
+ include common_expressions 'expressions.rl';
4
+ include common_machines 'machines.rl';
5
+
@@ -0,0 +1,38 @@
1
+ %%{
2
+ machine common_expressions;
3
+
4
+ kw_class = 'class';
5
+ kw_module = 'module';
6
+ kw_def = 'def';
7
+ kw_begin = 'begin';
8
+ kw_case = 'case';
9
+ kw_if = 'if';
10
+ kw_unless = 'unless';
11
+ kw_do = 'do';
12
+ kw_then = 'then';
13
+ kw_for = 'for';
14
+ kw_while = 'while';
15
+ kw_until = 'until';
16
+ kw_end = 'end';
17
+
18
+ vchar = alnum | '_';
19
+ const = upper . vchar* . ('::' . alpha . vchar*)*;
20
+ var = (lower | '_') . vchar*;
21
+ meth = (alpha | '_') . vchar*;
22
+ symbol = ':' . (var | const);
23
+ assoc = '=>';
24
+ assgn = '=';
25
+ comma = ',';
26
+ label = (var | const) . ':';
27
+
28
+ lparen = '(';
29
+ rparen = ')';
30
+ lbrace = '{';
31
+ rbrace = '}';
32
+ smcolon = ';';
33
+ newline = '\n';
34
+ bslash = '\\' . newline;
35
+ ospaces = space* -- newline;
36
+ mspaces = space+ -- newline;
37
+
38
+ }%%
@@ -1,70 +1,8 @@
1
- Sourcify.require_rb('proc', 'scanner', 'extensions')
2
-
3
- module Sourcify
4
- module Proc
5
- module Scanner #:nodoc:all
6
-
7
1
  %%{
8
- machine proc_scanner;
9
-
10
- kw_class = 'class';
11
- kw_module = 'module';
12
- kw_def = 'def';
13
- kw_begin = 'begin';
14
- kw_case = 'case';
15
- kw_if = 'if';
16
- kw_unless = 'unless';
17
- kw_do = 'do';
18
- kw_then = 'then';
19
- kw_for = 'for';
20
- kw_while = 'while';
21
- kw_until = 'until';
22
- kw_end = 'end';
23
-
24
- vchar = alnum | '_';
25
- const = upper . vchar* . ('::' . alpha . vchar*)*;
26
- var = (lower | '_') . vchar*;
27
- meth = (alpha | '_') . vchar*;
28
- symbol = ':' . (var | const);
29
- assoc = '=>';
30
- assgn = '=';
31
- comma = ',';
32
- label = (var | const) . ':';
2
+ machine common_machines;
33
3
 
34
- lparen = '(';
35
- rparen = ')';
36
- lbrace = '{';
37
- rbrace = '}';
38
- smcolon = ';';
39
- newline = '\n';
40
- bslash = '\\' . newline;
41
- ospaces = space* -- newline;
42
- mspaces = space+ -- newline;
43
-
44
- ## MACHINE >> New statement
45
- new_statement := |*
46
-
47
- (kw_for | kw_while | kw_until) . ^vchar => {
48
- push(:kw_do_alias2, ts, te)
49
- increment_counter(:do_end, 0..1)
50
- fgoto main;
51
- };
52
-
53
- (
54
- ((kw_class | kw_module | kw_def | kw_begin | kw_case | kw_if | kw_unless) . ^vchar) |
55
- (kw_class . ospaces . '<<' . ospaces . ^newline+)
56
- ) => {
57
- push(:kw_do_alias1, ts, te)
58
- increment_counter(:do_end, 1)
59
- fgoto main;
60
- };
61
-
62
- ospaces => { push(:space, ts, te) };
63
- any => { fhold; fgoto main; };
64
-
65
- *|;
4
+ ## MACHINE >> One-liner comment
66
5
 
67
- ## MACHINE >> One-liner comment
68
6
  per_line_comment := |*
69
7
  ^newline* => {
70
8
  push(:comment, ts.pred, te)
@@ -72,7 +10,8 @@ module Sourcify
72
10
  };
73
11
  *|;
74
12
 
75
- ## MACHINE >> Block comment
13
+ ## MACHINE >> Block comment
14
+
76
15
  block_comment := |*
77
16
  any* . newline . '=end' . ospaces . ^newline* => {
78
17
  unless push_comment(ts, te)
@@ -81,7 +20,8 @@ module Sourcify
81
20
  };
82
21
  *|;
83
22
 
84
- ## MACHINE >> Heredoc
23
+ ## MACHINE >> Heredoc
24
+
85
25
  heredoc := |*
86
26
  ^newline* . newline . ospaces . ^newline+ => {
87
27
  unless push_heredoc(ts, te)
@@ -90,7 +30,8 @@ module Sourcify
90
30
  };
91
31
  *|;
92
32
 
93
- ## MACHINE >> String
33
+ ## MACHINE >> String
34
+
94
35
  string := |*
95
36
 
96
37
  sqm = '%q' | '%w';
@@ -174,7 +115,8 @@ module Sourcify
174
115
  };
175
116
  *|;
176
117
 
177
- ## MACHINES >> Double quote strings
118
+ ## MACHINES >> Double quote strings
119
+
178
120
  dstring1 := |*
179
121
  [^\"]*[\"] => {
180
122
  unless push_dstring(ts, te)
@@ -372,114 +314,4 @@ module Sourcify
372
314
  };
373
315
  *|;
374
316
 
375
- ## MACHINE >> Main
376
- main := |*
377
-
378
- ## == Start/end of do..end block
379
-
380
- kw_do => {
381
- push(:kw_do, ts, te)
382
- increment_counter(:do_end)
383
- fgoto new_statement;
384
- };
385
-
386
- kw_end => {
387
- push(:kw_end, ts, te)
388
- decrement_counter(:do_end)
389
- };
390
-
391
- ## == Start/end of {...} block
392
-
393
- lbrace => {
394
- push(:lbrace, ts, te)
395
- increment_counter(:brace)
396
- };
397
-
398
- rbrace => {
399
- push(:rbrace, ts, te)
400
- decrement_counter(:brace)
401
- };
402
-
403
- assoc => {
404
- push(:assoc, ts, te)
405
- fix_counter_false_start(:brace)
406
- };
407
-
408
- label => {
409
- push_label(ts, te)
410
- fix_counter_false_start(:brace)
411
- };
412
-
413
- ## == New statement
414
-
415
- newline => {
416
- push(:newline, ts, te)
417
- increment_lineno
418
- fgoto new_statement;
419
- };
420
-
421
- smcolon | lparen | assgn | kw_then | comma => {
422
- push(:newline_alias, ts, te)
423
- fgoto new_statement;
424
- };
425
-
426
- ## == Comment
427
-
428
- '#' => {
429
- fgoto per_line_comment;
430
- };
431
-
432
- newline . '=begin' . ospaces . (ospaces . ^newline+)* . newline => {
433
- push_comment(ts, te)
434
- increment_lineno
435
- fgoto block_comment;
436
- };
437
-
438
- ## == Strings
439
-
440
- ('<<' | '<<-') . ["']? . (const | var) . ["']? . newline => {
441
- push_heredoc(ts, te)
442
- increment_lineno
443
- fgoto heredoc;
444
- };
445
-
446
- ('"' | "'" | '`' | '%') => {
447
- fhold; fgoto string;
448
- };
449
-
450
- '/' => {
451
- if preceded_with?(:char, :digit, :var, :const, :symbol, :dstring, :sstring, ')', ']', '}')
452
- push(:op, ts, te)
453
- else
454
- fhold; fgoto string;
455
- end
456
- };
457
-
458
- ## == Misc
459
-
460
- var => { push(:var, ts, te) };
461
- bslash => { push(:bslash, ts, te) };
462
- const => { push(:const, ts, te) };
463
- symbol => { push(:symbol, ts, te) };
464
- mspaces => { push(:space, ts, te) };
465
- [0-9] => { push(:digit, ts, te) };
466
- lower => { push(:char, ts, te) };
467
- any => { push(:any, ts, te) };
468
-
469
- *|;
470
-
471
317
  }%%
472
- %% write data;
473
-
474
- extend Scanner::Extensions
475
-
476
- def self.execute!
477
- data = @data
478
- eof = data.length
479
- %% write init;
480
- %% write exec;
481
- end
482
-
483
- end
484
- end
485
- end
@@ -0,0 +1,4 @@
1
+ module Sourcify
2
+ class ParserInternalError < Exception; end
3
+ class CannotParseEvalCodeError < Exception; end
4
+ end
@@ -0,0 +1,134 @@
1
+ module Sourcify
2
+
3
+ class MultipleMatchingMethodsPerLineError < Exception; end
4
+ class NoMatchingMethodError < Exception; end
5
+ class CannotFindSourceLocationError < Exception; end
6
+ class PlatformNotSupportedError < Exception; end
7
+
8
+ IS_PLATFORM_SUPPORTED =
9
+ begin
10
+ [:source_location, :parameters].each{|meth| 1.method(:to_s).send(meth) }
11
+ raise PlatformNotSupportedError if RUBY_PLATFORM =~ /java/i
12
+ true
13
+ rescue NoMethodError, PlatformNotSupportedError
14
+ false
15
+ end
16
+
17
+ module Method
18
+
19
+ def self.included(base) #:nodoc:
20
+ base.class_eval do
21
+ Sourcify.require_rb('method', 'methods')
22
+ include Methods::ToSource
23
+ include Methods::ToSexp
24
+ include Methods::ToRawSource
25
+ end
26
+ end
27
+
28
+ module Stubs
29
+
30
+ ###
31
+ # Returns the code representation of this method. Unlike Method#to_raw_source,
32
+ # the returned code retains only the functional aspects, fluff like comments
33
+ # are stripped off.
34
+ #
35
+ # class MyMath
36
+ # def self.sum(x, y)
37
+ # x + y # (blah)
38
+ # end
39
+ # end
40
+ #
41
+ # MyMath.method(:sum).to_source
42
+ # # >> "def sum(x, y)
43
+ # # >> (x + y)
44
+ # # >> end"
45
+ #
46
+ # This works for method defined via Module#define_method as well. The following
47
+ # approach of defining method yields exactly the same result as above:
48
+ #
49
+ # class MyMath
50
+ # class << self
51
+ # define_method(:sum) do |x,y|
52
+ # x + y # (blah)
53
+ # end
54
+ # end
55
+ # end
56
+ #
57
+ # MyMath.method(:sum).to_source
58
+ # # >> "def sum(x, y)
59
+ # # >> (x + y)
60
+ # # >> end"
61
+ #
62
+ # The following options are supported:
63
+ #
64
+ # * +:strip_enclosure+ when set to true, strips the method enclosure to get
65
+ # just the meat within.
66
+ #
67
+ # MyMath.method(:sum).to_source(:strip_enclosure => true)
68
+ # # >> "(x + y)"
69
+ #
70
+ # * +:attached_to+ is useful ONLY when a method is defined via
71
+ # Module#define_method, pls see Sourcify::Proc::Stubs#to_source for more info.
72
+ #
73
+ # * +:ignore_nested+ is useful ONLY when a method is defined via
74
+ # Module#define_method, pls see Sourcify::Proc::Stubs#to_source for more info.
75
+ #
76
+ # * an optional +body_matcher+ block is supported as well, again this is ONLY
77
+ # useful for method defined via Module#define_method, pls see
78
+ # Sourcify::Proc::Stubs#to_source for more info.
79
+ #
80
+ def to_source(opts={}, &body_matcher)
81
+ # NOTE: this is a stub for the actual one in Methods::ToSource
82
+ end
83
+
84
+ ###
85
+ # Returns the S-expression representation of this method.
86
+ #
87
+ # class MyMath
88
+ # def self.sum(x, y)
89
+ # x + y # (blah)
90
+ # end
91
+ # end
92
+ #
93
+ # MyMath.method(:sum).to_sexp
94
+ # >> s(:defn,
95
+ # >> :sum,
96
+ # >> s(:args, :x, :y),
97
+ # >> s(:scope, s(:block, s(:call, s(:lvar, :x), :+, s(:arglist, s(:lvar, :y))))))
98
+ #
99
+ # This works for methods defined via Module#define_method as well. Pls see
100
+ # #to_source for options/arguments supported.
101
+ #
102
+ def to_sexp(opts={}, &body_matcher)
103
+ # NOTE: this is a stub for the actual one in Methods::ToSexp
104
+ end
105
+
106
+ ###
107
+ # Returns the raw code enclosed within this method.
108
+ #
109
+ # class MyMath
110
+ # def self.sum(x, y)
111
+ # x + y # (blah)
112
+ # end
113
+ # end
114
+ #
115
+ # MyMath.method(:sum).to_raw_source
116
+ # >> "def sum(x, y)
117
+ # >> x + y # (blah)
118
+ # >> end"
119
+ #
120
+ # This works for methods defined via Module#define_method as well. Pls see
121
+ # #to_source for options/arguments supported.
122
+ #
123
+ def to_raw_source(opts={}, &body_matcher)
124
+ # NOTE: this is a stub for the actual one in Methods::ToRawSource
125
+ end
126
+
127
+ end
128
+
129
+ end
130
+ end
131
+
132
+ Method.class_eval do
133
+ include Sourcify::Method
134
+ end