laser 0.7.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/LICENSE +661 -0
- data/README.md +158 -0
- data/Rakefile +104 -0
- data/VERSION +1 -0
- data/bin/laser +7 -0
- data/design_docs/goals.md +57 -0
- data/design_docs/object_regex.md +426 -0
- data/design_docs/type_annotations.md +80 -0
- data/ext/laser/BasicBlock.cpp +572 -0
- data/ext/laser/BasicBlock.h +118 -0
- data/ext/laser/extconf.rb +3 -0
- data/features/laser.feature +25 -0
- data/features/step_definitions/laser_steps.rb +39 -0
- data/features/support/env.rb +14 -0
- data/features/support/testdata/1_input +1 -0
- data/features/support/testdata/1_output +1 -0
- data/features/support/testdata/2_input +4 -0
- data/features/support/testdata/2_output +4 -0
- data/features/support/testdata/3_input +8 -0
- data/features/support/testdata/3_output +11 -0
- data/features/support/testdata/4_input +5 -0
- data/features/support/testdata/4_output +5 -0
- data/features/support/testdata/5_input +13 -0
- data/laser.gemspec +382 -0
- data/lib/laser.rb +98 -0
- data/lib/laser/analysis/annotations.rb +95 -0
- data/lib/laser/analysis/annotations/annotation_config.yaml +3 -0
- data/lib/laser/analysis/annotations/comment_attachment_annotation.rb +66 -0
- data/lib/laser/analysis/annotations/node_pointers_annotation.rb +36 -0
- data/lib/laser/analysis/annotations/runtime_annotation.rb +55 -0
- data/lib/laser/analysis/argument_expansion.rb +132 -0
- data/lib/laser/analysis/arity.rb +34 -0
- data/lib/laser/analysis/bindings.rb +144 -0
- data/lib/laser/analysis/bootstrap/bootstrap.rb +298 -0
- data/lib/laser/analysis/bootstrap/laser_class.rb +106 -0
- data/lib/laser/analysis/bootstrap/laser_method.rb +255 -0
- data/lib/laser/analysis/bootstrap/laser_module.rb +403 -0
- data/lib/laser/analysis/bootstrap/laser_module_copy.rb +74 -0
- data/lib/laser/analysis/bootstrap/laser_object.rb +69 -0
- data/lib/laser/analysis/bootstrap/laser_proc.rb +150 -0
- data/lib/laser/analysis/bootstrap/laser_singleton_class.rb +44 -0
- data/lib/laser/analysis/comments.rb +35 -0
- data/lib/laser/analysis/control_flow.rb +28 -0
- data/lib/laser/analysis/control_flow/alias_analysis.rb +31 -0
- data/lib/laser/analysis/control_flow/basic_block.rb +105 -0
- data/lib/laser/analysis/control_flow/cfg_builder.rb +2505 -0
- data/lib/laser/analysis/control_flow/cfg_instruction.rb +190 -0
- data/lib/laser/analysis/control_flow/constant_propagation.rb +742 -0
- data/lib/laser/analysis/control_flow/control_flow_graph.rb +370 -0
- data/lib/laser/analysis/control_flow/lifetime_analysis.rb +91 -0
- data/lib/laser/analysis/control_flow/method_call_search.rb +26 -0
- data/lib/laser/analysis/control_flow/raise_properties.rb +25 -0
- data/lib/laser/analysis/control_flow/simulation.rb +385 -0
- data/lib/laser/analysis/control_flow/static_single_assignment.rb +185 -0
- data/lib/laser/analysis/control_flow/unreachability_analysis.rb +57 -0
- data/lib/laser/analysis/control_flow/unused_variables.rb +91 -0
- data/lib/laser/analysis/control_flow/yield_properties.rb +103 -0
- data/lib/laser/analysis/errors.rb +131 -0
- data/lib/laser/analysis/laser_utils.rb +18 -0
- data/lib/laser/analysis/lexical_analysis.rb +172 -0
- data/lib/laser/analysis/method_call.rb +68 -0
- data/lib/laser/analysis/protocol_registry.rb +30 -0
- data/lib/laser/analysis/scope.rb +118 -0
- data/lib/laser/analysis/sexp.rb +159 -0
- data/lib/laser/analysis/sexp_analysis.rb +40 -0
- data/lib/laser/analysis/sexp_extensions/constant_extraction.rb +115 -0
- data/lib/laser/analysis/sexp_extensions/source_location.rb +164 -0
- data/lib/laser/analysis/sexp_extensions/type_inference.rb +47 -0
- data/lib/laser/analysis/signature.rb +76 -0
- data/lib/laser/analysis/special_methods/send.rb +67 -0
- data/lib/laser/analysis/unused_methods.rb +21 -0
- data/lib/laser/analysis/visitor.rb +141 -0
- data/lib/laser/annotation_parser/annotations.treetop +126 -0
- data/lib/laser/annotation_parser/annotations_parser.rb +748 -0
- data/lib/laser/annotation_parser/class_annotations.treetop +82 -0
- data/lib/laser/annotation_parser/class_annotations_parser.rb +654 -0
- data/lib/laser/annotation_parser/overload.treetop +24 -0
- data/lib/laser/annotation_parser/overload_parser.rb +167 -0
- data/lib/laser/annotation_parser/parsers.rb +6 -0
- data/lib/laser/annotation_parser/structural.treetop +37 -0
- data/lib/laser/annotation_parser/structural_parser.rb +406 -0
- data/lib/laser/annotation_parser/useful_parsers.treetop +47 -0
- data/lib/laser/annotation_parser/useful_parsers_parser.rb +674 -0
- data/lib/laser/rake/task.rb +46 -0
- data/lib/laser/runner.rb +189 -0
- data/lib/laser/scanner.rb +169 -0
- data/lib/laser/standard_library/_thread.rb +110 -0
- data/lib/laser/standard_library/abbrev.rb +103 -0
- data/lib/laser/standard_library/array.rb +418 -0
- data/lib/laser/standard_library/base64.rb +91 -0
- data/lib/laser/standard_library/basic_object.rb +55 -0
- data/lib/laser/standard_library/benchmark.rb +556 -0
- data/lib/laser/standard_library/bignum.rb +185 -0
- data/lib/laser/standard_library/cgi.rb +275 -0
- data/lib/laser/standard_library/cgi/cookie.rb +147 -0
- data/lib/laser/standard_library/cgi/core.rb +791 -0
- data/lib/laser/standard_library/cgi/html.rb +1021 -0
- data/lib/laser/standard_library/cgi/session.rb +537 -0
- data/lib/laser/standard_library/cgi/session/pstore.rb +111 -0
- data/lib/laser/standard_library/cgi/util.rb +188 -0
- data/lib/laser/standard_library/class_definitions.rb +333 -0
- data/lib/laser/standard_library/comparable.rb +125 -0
- data/lib/laser/standard_library/complex.rb +162 -0
- data/lib/laser/standard_library/enumerable.rb +178 -0
- data/lib/laser/standard_library/exceptions.rb +135 -0
- data/lib/laser/standard_library/fixnum.rb +188 -0
- data/lib/laser/standard_library/float.rb +180 -0
- data/lib/laser/standard_library/hash.rb +237 -0
- data/lib/laser/standard_library/integer.rb +123 -0
- data/lib/laser/standard_library/laser_magic.rb +7 -0
- data/lib/laser/standard_library/nil_false_true.rb +113 -0
- data/lib/laser/standard_library/numbers.rb +192 -0
- data/lib/laser/standard_library/proc.rb +31 -0
- data/lib/laser/standard_library/set.rb +1348 -0
- data/lib/laser/standard_library/string.rb +666 -0
- data/lib/laser/standard_library/stringio.rb +2 -0
- data/lib/laser/standard_library/symbol.rb +125 -0
- data/lib/laser/standard_library/tsort.rb +242 -0
- data/lib/laser/support/acts_as_struct.rb +66 -0
- data/lib/laser/support/frequency.rb +55 -0
- data/lib/laser/support/inheritable_attributes.rb +145 -0
- data/lib/laser/support/module_extensions.rb +94 -0
- data/lib/laser/support/placeholder_object.rb +13 -0
- data/lib/laser/third_party/rgl/adjacency.rb +221 -0
- data/lib/laser/third_party/rgl/base.rb +228 -0
- data/lib/laser/third_party/rgl/bidirectional.rb +39 -0
- data/lib/laser/third_party/rgl/condensation.rb +47 -0
- data/lib/laser/third_party/rgl/connected_components.rb +138 -0
- data/lib/laser/third_party/rgl/control_flow.rb +170 -0
- data/lib/laser/third_party/rgl/depth_first_spanning_tree.rb +37 -0
- data/lib/laser/third_party/rgl/dominators.rb +124 -0
- data/lib/laser/third_party/rgl/dot.rb +93 -0
- data/lib/laser/third_party/rgl/graphxml.rb +51 -0
- data/lib/laser/third_party/rgl/implicit.rb +174 -0
- data/lib/laser/third_party/rgl/mutable.rb +117 -0
- data/lib/laser/third_party/rgl/rdot.rb +445 -0
- data/lib/laser/third_party/rgl/topsort.rb +72 -0
- data/lib/laser/third_party/rgl/transitivity.rb +180 -0
- data/lib/laser/third_party/rgl/traversal.rb +348 -0
- data/lib/laser/types/types.rb +433 -0
- data/lib/laser/version.rb +14 -0
- data/lib/laser/warning.rb +149 -0
- data/lib/laser/warning_sets/default.yml +13 -0
- data/lib/laser/warnings/assignment_in_condition.rb +20 -0
- data/lib/laser/warnings/comment_spacing.rb +31 -0
- data/lib/laser/warnings/extra_blank_lines.rb +30 -0
- data/lib/laser/warnings/extra_whitespace.rb +16 -0
- data/lib/laser/warnings/hash_symbol_18_warning.rb +63 -0
- data/lib/laser/warnings/hash_symbol_19_warning.rb +29 -0
- data/lib/laser/warnings/line_length.rb +115 -0
- data/lib/laser/warnings/misaligned_unindentation.rb +17 -0
- data/lib/laser/warnings/operator_spacing.rb +68 -0
- data/lib/laser/warnings/parens_on_declaration.rb +30 -0
- data/lib/laser/warnings/rescue_exception.rb +42 -0
- data/lib/laser/warnings/semicolon.rb +25 -0
- data/lib/laser/warnings/sexp_errors.rb +24 -0
- data/lib/laser/warnings/uncalled_method_warning.rb +7 -0
- data/lib/laser/warnings/useless_double_quotes.rb +38 -0
- data/spec/analysis_specs/annotations_spec.rb +47 -0
- data/spec/analysis_specs/annotations_specs/comment_attachment_spec.rb +68 -0
- data/spec/analysis_specs/annotations_specs/node_pointers_annotation_spec.rb +90 -0
- data/spec/analysis_specs/annotations_specs/runtime_annotation_spec.rb +135 -0
- data/spec/analysis_specs/annotations_specs/spec_helper.rb +33 -0
- data/spec/analysis_specs/argument_expansion_spec.rb +113 -0
- data/spec/analysis_specs/bindings_spec.rb +36 -0
- data/spec/analysis_specs/comment_spec.rb +93 -0
- data/spec/analysis_specs/control_flow_specs/cfg_instruction_spec.rb +111 -0
- data/spec/analysis_specs/control_flow_specs/constant_propagation_spec.rb +560 -0
- data/spec/analysis_specs/control_flow_specs/control_flow_graph_spec.rb +5 -0
- data/spec/analysis_specs/control_flow_specs/raise_properties_spec.rb +310 -0
- data/spec/analysis_specs/control_flow_specs/raise_type_inference_spec.rb +301 -0
- data/spec/analysis_specs/control_flow_specs/return_type_inference_spec.rb +431 -0
- data/spec/analysis_specs/control_flow_specs/simulation_spec.rb +158 -0
- data/spec/analysis_specs/control_flow_specs/spec_helper.rb +110 -0
- data/spec/analysis_specs/control_flow_specs/tuple_misuse_inference_spec.rb +125 -0
- data/spec/analysis_specs/control_flow_specs/unreachability_analysis_spec.rb +76 -0
- data/spec/analysis_specs/control_flow_specs/unused_variable_spec.rb +99 -0
- data/spec/analysis_specs/control_flow_specs/yield_properties_spec.rb +372 -0
- data/spec/analysis_specs/error_spec.rb +30 -0
- data/spec/analysis_specs/laser_class_spec.rb +322 -0
- data/spec/analysis_specs/lexical_analysis_spec.rb +184 -0
- data/spec/analysis_specs/protocol_registry_spec.rb +63 -0
- data/spec/analysis_specs/scope_annotation_spec.rb +1013 -0
- data/spec/analysis_specs/scope_spec.rb +126 -0
- data/spec/analysis_specs/sexp_analysis_spec.rb +30 -0
- data/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb +309 -0
- data/spec/analysis_specs/sexp_extension_specs/source_location_spec.rb +231 -0
- data/spec/analysis_specs/sexp_extension_specs/spec_helper.rb +1 -0
- data/spec/analysis_specs/sexp_extension_specs/type_inference_spec.rb +252 -0
- data/spec/analysis_specs/sexp_spec.rb +167 -0
- data/spec/analysis_specs/spec_helper.rb +27 -0
- data/spec/analysis_specs/unused_methods_spec.rb +65 -0
- data/spec/analysis_specs/visitor_spec.rb +64 -0
- data/spec/annotation_parser_specs/annotations_parser_spec.rb +89 -0
- data/spec/annotation_parser_specs/class_annotation_parser_spec.rb +120 -0
- data/spec/annotation_parser_specs/overload_parser_spec.rb +39 -0
- data/spec/annotation_parser_specs/parsers_spec.rb +14 -0
- data/spec/annotation_parser_specs/spec_helper.rb +1 -0
- data/spec/annotation_parser_specs/structural_parser_spec.rb +67 -0
- data/spec/laser_spec.rb +14 -0
- data/spec/rake_specs/spec_helper.rb +1 -0
- data/spec/rake_specs/task_spec.rb +67 -0
- data/spec/runner_spec.rb +207 -0
- data/spec/scanner_spec.rb +75 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/standard_library/exceptions_spec.rb +19 -0
- data/spec/standard_library/globals_spec.rb +14 -0
- data/spec/standard_library/set_spec.rb +31 -0
- data/spec/standard_library/spec_helper.rb +1 -0
- data/spec/standard_library/standard_library_spec.rb +302 -0
- data/spec/support_specs/acts_as_struct_spec.rb +94 -0
- data/spec/support_specs/frequency_spec.rb +23 -0
- data/spec/support_specs/module_extensions_spec.rb +117 -0
- data/spec/support_specs/spec_helper.rb +1 -0
- data/spec/type_specs/spec_helper.rb +1 -0
- data/spec/type_specs/types_spec.rb +133 -0
- data/spec/warning_spec.rb +95 -0
- data/spec/warning_specs/assignment_in_condition_spec.rb +68 -0
- data/spec/warning_specs/comment_spacing_spec.rb +65 -0
- data/spec/warning_specs/extra_blank_lines_spec.rb +70 -0
- data/spec/warning_specs/extra_whitespace_spec.rb +33 -0
- data/spec/warning_specs/hash_symbol_18_warning_spec.rb +89 -0
- data/spec/warning_specs/hash_symbol_19_warning_spec.rb +63 -0
- data/spec/warning_specs/line_length_spec.rb +173 -0
- data/spec/warning_specs/misaligned_unindentation_spec.rb +35 -0
- data/spec/warning_specs/operator_spacing_spec.rb +104 -0
- data/spec/warning_specs/parens_on_declaration_spec.rb +57 -0
- data/spec/warning_specs/rescue_exception_spec.rb +105 -0
- data/spec/warning_specs/semicolon_spec.rb +58 -0
- data/spec/warning_specs/spec_helper.rb +1 -0
- data/spec/warning_specs/useless_double_quotes_spec.rb +74 -0
- data/status_reports/2010/12/2010-12-14.md +163 -0
- data/status_reports/2010/12/2010-12-23.md +298 -0
- data/status_reports/2010/12/2010-12-24.md +6 -0
- data/test/third_party_tests/rgl_tests/TestComponents.rb +65 -0
- data/test/third_party_tests/rgl_tests/TestCycles.rb +61 -0
- data/test/third_party_tests/rgl_tests/TestDirectedGraph.rb +125 -0
- data/test/third_party_tests/rgl_tests/TestDot.rb +18 -0
- data/test/third_party_tests/rgl_tests/TestEdge.rb +34 -0
- data/test/third_party_tests/rgl_tests/TestGraph.rb +71 -0
- data/test/third_party_tests/rgl_tests/TestGraphXML.rb +57 -0
- data/test/third_party_tests/rgl_tests/TestImplicit.rb +52 -0
- data/test/third_party_tests/rgl_tests/TestRdot.rb +863 -0
- data/test/third_party_tests/rgl_tests/TestTransitivity.rb +129 -0
- data/test/third_party_tests/rgl_tests/TestTraversal.rb +220 -0
- data/test/third_party_tests/rgl_tests/TestUnDirectedGraph.rb +102 -0
- data/test/third_party_tests/rgl_tests/examples/north/Graph.log +128 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.0.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.1.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.11.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.12.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.13.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.14.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.15.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.16.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.17.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.19.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.2.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.20.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.22.graphml +43 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.24.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.25.graphml +45 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.27.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.28.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.29.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.3.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.30.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.31.graphml +42 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.34.graphml +42 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.37.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.38.graphml +38 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.39.graphml +36 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.4.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.40.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.41.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.42.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.45.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.46.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.5.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.50.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.56.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.57.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.58.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.6.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.60.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.61.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.62.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.68.graphml +30 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.69.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.7.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.70.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.71.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.72.graphml +28 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.74.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.75.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.78.graphml +27 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.79.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.8.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.80.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.82.graphml +35 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.83.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.85.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.86.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.88.graphml +37 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.89.graphml +29 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.9.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.90.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.91.graphml +31 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.92.graphml +26 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.93.graphml +32 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.10.94.graphml +34 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.12.8.graphml +40 -0
- data/test/third_party_tests/rgl_tests/examples/north/g.14.9.graphml +36 -0
- data/test/third_party_tests/rgl_tests/test_helper.rb +7 -0
- data/test/third_party_tests/test_inheritable_attributes.rb +187 -0
- metadata +470 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
##
|
2
|
+
# LICENSING: Taken from Rubinius.
|
3
|
+
# Retrieved from https://github.com/rubinius/rubinius/blob/master/kernel/common/comparable.rb
|
4
|
+
# on 7/25/2011
|
5
|
+
# commit de03069d21839235fd59
|
6
|
+
#
|
7
|
+
# The Comparable mixin is used by classes whose objects may be ordered. The
|
8
|
+
# class must define the <tt><=></tt> (spaceship) operator, which compares the
|
9
|
+
# receiver against another object, returning -1, 0, or +1 depending on whether
|
10
|
+
# the receiver is less than, equal to, or greater than the other object.
|
11
|
+
#
|
12
|
+
# Comparable uses <tt><=></tt> to implement the conventional comparison
|
13
|
+
# operators (<tt><</tt>, <tt><=</tt>, <tt>==</tt>, <tt>>=</tt>, and
|
14
|
+
# <tt>></tt>) and the method <tt>between?</tt>.
|
15
|
+
#
|
16
|
+
# class SizeMatters
|
17
|
+
# include Comparable
|
18
|
+
# attr :str
|
19
|
+
# def <=>(other)
|
20
|
+
# str.size <=> other.str.size
|
21
|
+
# end
|
22
|
+
# def initialize(str)
|
23
|
+
# @str = str
|
24
|
+
# end
|
25
|
+
# def inspect
|
26
|
+
# @str
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# s1 = SizeMatters.new "Z"
|
31
|
+
# s2 = SizeMatters.new "YY"
|
32
|
+
# s3 = SizeMatters.new "XXX"
|
33
|
+
# s4 = SizeMatters.new "WWWW"
|
34
|
+
# s5 = SizeMatters.new "VVVVV"
|
35
|
+
#
|
36
|
+
# s1 < s2 #=> true
|
37
|
+
# s4.between? s1, s3 #=> false
|
38
|
+
# s4.between? s3, s5 #=> true
|
39
|
+
# [ s3, s2, s5, s4, s1 ].sort #=> [Z, YY, XXX, WWWW, VVVVV]
|
40
|
+
|
41
|
+
module Comparable
|
42
|
+
|
43
|
+
# Compares two objects based on the receiver's <code><=></code>
|
44
|
+
# method, returning true if it returns 0. Also returns true if
|
45
|
+
# _obj_ and _other_ are the same object.
|
46
|
+
def ==(other)
|
47
|
+
return true if equal?(other)
|
48
|
+
|
49
|
+
begin
|
50
|
+
unless comp = (self <=> other)
|
51
|
+
return nil
|
52
|
+
end
|
53
|
+
|
54
|
+
return Comparable.compare_int(comp) == 0
|
55
|
+
rescue StandardError
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Compares two objects based on the receiver's <code><=></code>
|
61
|
+
# method, returning true if it returns 1.
|
62
|
+
def >(other)
|
63
|
+
unless comp = (self <=> other)
|
64
|
+
raise ArgumentError, "comparison of #{self.class} with #{other.class}"
|
65
|
+
end
|
66
|
+
|
67
|
+
Comparable.compare_int(comp) > 0
|
68
|
+
end
|
69
|
+
|
70
|
+
# Compares two objects based on the receiver's <code><=></code>
|
71
|
+
# method, returning true if it returns 0 or 1.
|
72
|
+
def >=(other)
|
73
|
+
unless comp = (self <=> other)
|
74
|
+
raise ArgumentError, "comparison of #{self.class} with #{other.class}"
|
75
|
+
end
|
76
|
+
|
77
|
+
Comparable.compare_int(comp) >= 0
|
78
|
+
end
|
79
|
+
|
80
|
+
# Compares two objects based on the receiver's <code><=></code>
|
81
|
+
# method, returning true if it returns -1.
|
82
|
+
def <(other)
|
83
|
+
unless comp = (self <=> other)
|
84
|
+
raise ArgumentError, "comparison of #{self.class} with #{other.class}"
|
85
|
+
end
|
86
|
+
|
87
|
+
Comparable.compare_int(comp) < 0
|
88
|
+
end
|
89
|
+
|
90
|
+
# Compares two objects based on the receiver's <code><=></code>
|
91
|
+
# method, returning true if it returns -1 or 0.
|
92
|
+
def <=(other)
|
93
|
+
unless comp = (self <=> other)
|
94
|
+
raise ArgumentError, "comparison of #{self.class} with #{other.class}"
|
95
|
+
end
|
96
|
+
|
97
|
+
Comparable.compare_int(comp) <= 0
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns <code>false</code> if <i>obj</i> <code><=></code>
|
101
|
+
# <i>min</i> is less than zero or if <i>anObject</i> <code><=></code>
|
102
|
+
# <i>max</i> is greater than zero, <code>true</code> otherwise.
|
103
|
+
#
|
104
|
+
# 3.between?(1, 5) #=> true
|
105
|
+
# 6.between?(1, 5) #=> false
|
106
|
+
# 'cat'.between?('ant', 'dog') #=> true
|
107
|
+
# 'gnu'.between?('ant', 'dog') #=> false
|
108
|
+
#
|
109
|
+
def between?(min, max)
|
110
|
+
# This could be more elegant, but we need to use <= and => on self to match
|
111
|
+
# MRI.
|
112
|
+
return false if self < min
|
113
|
+
return false if self > max
|
114
|
+
return true
|
115
|
+
end
|
116
|
+
|
117
|
+
# A version of MRI's rb_cmpint (sort of)
|
118
|
+
def self.compare_int(int)
|
119
|
+
return int if int.kind_of? Fixnum
|
120
|
+
|
121
|
+
return 1 if int > 0
|
122
|
+
return -1 if int < 0
|
123
|
+
return 0
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
class Complex
|
2
|
+
# pure: true
|
3
|
+
# builtin: true
|
4
|
+
# returns: Complex=
|
5
|
+
def *(other)
|
6
|
+
end
|
7
|
+
# pure: true
|
8
|
+
# builtin: true
|
9
|
+
# returns: Complex=
|
10
|
+
def **(other)
|
11
|
+
end
|
12
|
+
# pure: true
|
13
|
+
# builtin: true
|
14
|
+
# returns: Complex=
|
15
|
+
def +(other)
|
16
|
+
end
|
17
|
+
# pure: true
|
18
|
+
# builtin: true
|
19
|
+
# returns: Complex=
|
20
|
+
def -(other)
|
21
|
+
end
|
22
|
+
# pure: true
|
23
|
+
# builtin: true
|
24
|
+
# returns: Complex=
|
25
|
+
def -@
|
26
|
+
end
|
27
|
+
# pure: true
|
28
|
+
# builtin: true
|
29
|
+
# returns: Complex=
|
30
|
+
def /(other)
|
31
|
+
end
|
32
|
+
# pure: true
|
33
|
+
# builtin: true
|
34
|
+
# returns: Boolean
|
35
|
+
# raises: never
|
36
|
+
def ==(other)
|
37
|
+
end
|
38
|
+
# pure: true
|
39
|
+
# builtin: true
|
40
|
+
# returns: Float= | Fixnum= | Bignum=
|
41
|
+
# raises: never
|
42
|
+
def abs
|
43
|
+
end
|
44
|
+
alias magnitude abs
|
45
|
+
# pure: true
|
46
|
+
# builtin: true
|
47
|
+
# returns: Float= | Fixnum= | Bignum=
|
48
|
+
# raises: never
|
49
|
+
def abs2
|
50
|
+
end
|
51
|
+
# pure: true
|
52
|
+
# builtin: true
|
53
|
+
# returns: Float=
|
54
|
+
# raises: never
|
55
|
+
def angle
|
56
|
+
end
|
57
|
+
alias arg angle
|
58
|
+
alias phase angle
|
59
|
+
def coerce(other)
|
60
|
+
end
|
61
|
+
# pure: true
|
62
|
+
# builtin: true
|
63
|
+
# returns: Complex=
|
64
|
+
# raises: never
|
65
|
+
def conj
|
66
|
+
end
|
67
|
+
alias conjugate conj
|
68
|
+
# pure: true
|
69
|
+
# builtin: true
|
70
|
+
# returns: Fixnum= | Bignum=
|
71
|
+
# raises: never
|
72
|
+
def denominator
|
73
|
+
end
|
74
|
+
# pure: true
|
75
|
+
# builtin: true
|
76
|
+
# returns: Boolean
|
77
|
+
# raises: never
|
78
|
+
def eql?(other)
|
79
|
+
end
|
80
|
+
# pure: true
|
81
|
+
# builtin: true
|
82
|
+
# returns: Complex=
|
83
|
+
# raises: never
|
84
|
+
def fdiv(other)
|
85
|
+
end
|
86
|
+
# pure: true
|
87
|
+
# builtin: true
|
88
|
+
# returns: Fixnum= | Bignum=
|
89
|
+
# raises: never
|
90
|
+
def hash
|
91
|
+
end
|
92
|
+
# pure: true
|
93
|
+
# builtin: true
|
94
|
+
# returns: Float= | Fixnum= | Bignum=
|
95
|
+
# raises: never
|
96
|
+
def imag
|
97
|
+
end
|
98
|
+
alias imaginary imag
|
99
|
+
# pure: true
|
100
|
+
# builtin: true
|
101
|
+
# returns: String=
|
102
|
+
def inspect
|
103
|
+
end
|
104
|
+
# pure: true
|
105
|
+
# builtin: true
|
106
|
+
# returns: Complex=
|
107
|
+
# raises: never
|
108
|
+
def numerator
|
109
|
+
end
|
110
|
+
# pure: true
|
111
|
+
# builtin: true
|
112
|
+
# returns: Array=
|
113
|
+
# raises: never
|
114
|
+
def polar
|
115
|
+
end
|
116
|
+
alias quo /
|
117
|
+
# pure: true
|
118
|
+
# builtin: true
|
119
|
+
# returns: Rational=
|
120
|
+
def rationalize(eps=nil)
|
121
|
+
end
|
122
|
+
# pure: true
|
123
|
+
# builtin: true
|
124
|
+
# returns: Float= | Fixnum= | Bignum=
|
125
|
+
# raises: never
|
126
|
+
def real
|
127
|
+
end
|
128
|
+
# pure: true
|
129
|
+
# builtin: true
|
130
|
+
# returns: Boolean
|
131
|
+
# raises: never
|
132
|
+
def real?
|
133
|
+
end
|
134
|
+
# pure: true
|
135
|
+
# builtin: true
|
136
|
+
# returns: Array=
|
137
|
+
# raises: never
|
138
|
+
def rect
|
139
|
+
end
|
140
|
+
alias rectangular rect
|
141
|
+
# pure: true
|
142
|
+
# builtin: true
|
143
|
+
# returns: Float=
|
144
|
+
def to_f
|
145
|
+
end
|
146
|
+
# pure: true
|
147
|
+
# builtin: true
|
148
|
+
# returns: Integer=
|
149
|
+
def to_i
|
150
|
+
end
|
151
|
+
# pure: true
|
152
|
+
# builtin: true
|
153
|
+
# returns: Rational=
|
154
|
+
def to_r
|
155
|
+
end
|
156
|
+
# pure: true
|
157
|
+
# builtin: true
|
158
|
+
# returns: String=
|
159
|
+
# raises: never
|
160
|
+
def to_s
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
module Enumerable
|
2
|
+
# builtin: true
|
3
|
+
# pure: true
|
4
|
+
def all?
|
5
|
+
end
|
6
|
+
# builtin: true
|
7
|
+
# pure: true
|
8
|
+
def any?
|
9
|
+
end
|
10
|
+
# builtin: true
|
11
|
+
# pure: true
|
12
|
+
def chunk(initial_state = nil)
|
13
|
+
end
|
14
|
+
# builtin: true
|
15
|
+
# pure: true
|
16
|
+
def collect
|
17
|
+
end
|
18
|
+
# builtin: true
|
19
|
+
# pure: true
|
20
|
+
def collect_concat
|
21
|
+
end
|
22
|
+
# builtin: true
|
23
|
+
# pure: true
|
24
|
+
def count(*args)
|
25
|
+
end
|
26
|
+
# builtin: true
|
27
|
+
# pure: true
|
28
|
+
def cycle(n=nil)
|
29
|
+
end
|
30
|
+
# builtin: true
|
31
|
+
# pure: true
|
32
|
+
def detect(ifnone=nil)
|
33
|
+
end
|
34
|
+
# builtin: true
|
35
|
+
# pure: true
|
36
|
+
def drop(n)
|
37
|
+
end
|
38
|
+
# builtin: true
|
39
|
+
# pure: true
|
40
|
+
def drop_while
|
41
|
+
end
|
42
|
+
# builtin: true
|
43
|
+
# pure: true
|
44
|
+
def each_cons(n)
|
45
|
+
end
|
46
|
+
# builtin: true
|
47
|
+
# pure: true
|
48
|
+
def each_entry
|
49
|
+
end
|
50
|
+
# builtin: true
|
51
|
+
# pure: true
|
52
|
+
def each_slice(n)
|
53
|
+
end
|
54
|
+
# builtin: true
|
55
|
+
# pure: true
|
56
|
+
def each_with_index(*args)
|
57
|
+
end
|
58
|
+
# builtin: true
|
59
|
+
# pure: true
|
60
|
+
def each_with_object(obj)
|
61
|
+
end
|
62
|
+
# builtin: true
|
63
|
+
# pure: true
|
64
|
+
def entries
|
65
|
+
end
|
66
|
+
alias find detect
|
67
|
+
# builtin: true
|
68
|
+
# pure: true
|
69
|
+
def find_index(*args)
|
70
|
+
end
|
71
|
+
# builtin: true
|
72
|
+
# pure: true
|
73
|
+
def first(n=nil)
|
74
|
+
end
|
75
|
+
# builtin: true
|
76
|
+
# pure: true
|
77
|
+
def flat_map
|
78
|
+
end
|
79
|
+
# builtin: true
|
80
|
+
# pure: true
|
81
|
+
def grep(pattern)
|
82
|
+
end
|
83
|
+
# builtin: true
|
84
|
+
# pure: true
|
85
|
+
def group_by
|
86
|
+
end
|
87
|
+
# builtin: true
|
88
|
+
# pure: true
|
89
|
+
def include?(obj)
|
90
|
+
end
|
91
|
+
# builtin: true
|
92
|
+
# pure: true
|
93
|
+
def inject(*args)
|
94
|
+
end
|
95
|
+
# builtin: true
|
96
|
+
# pure: true
|
97
|
+
def map
|
98
|
+
end
|
99
|
+
# builtin: true
|
100
|
+
# pure: true
|
101
|
+
def max
|
102
|
+
end
|
103
|
+
# builtin: true
|
104
|
+
# pure: true
|
105
|
+
def max_by
|
106
|
+
end
|
107
|
+
alias member? include?
|
108
|
+
# builtin: true
|
109
|
+
# pure: true
|
110
|
+
def min
|
111
|
+
end
|
112
|
+
# builtin: true
|
113
|
+
# pure: true
|
114
|
+
def min_by
|
115
|
+
end
|
116
|
+
# builtin: true
|
117
|
+
# pure: true
|
118
|
+
def minmax
|
119
|
+
end
|
120
|
+
# builtin: true
|
121
|
+
# pure: true
|
122
|
+
def minmax_by
|
123
|
+
end
|
124
|
+
# builtin: true
|
125
|
+
# pure: true
|
126
|
+
def none?
|
127
|
+
end
|
128
|
+
# builtin: true
|
129
|
+
# pure: true
|
130
|
+
def one?
|
131
|
+
end
|
132
|
+
# builtin: true
|
133
|
+
# pure: true
|
134
|
+
def partition
|
135
|
+
end
|
136
|
+
alias reduce inject
|
137
|
+
# builtin: true
|
138
|
+
# pure: true
|
139
|
+
def reject
|
140
|
+
end
|
141
|
+
# builtin: true
|
142
|
+
# pure: true
|
143
|
+
def reverse_each(*args)
|
144
|
+
end
|
145
|
+
# builtin: true
|
146
|
+
# pure: true
|
147
|
+
def select()
|
148
|
+
end
|
149
|
+
alias find_all select
|
150
|
+
# builtin: true
|
151
|
+
# pure: true
|
152
|
+
def slice_before(first_arg=nil)
|
153
|
+
end
|
154
|
+
# builtin: true
|
155
|
+
# pure: true
|
156
|
+
def sort
|
157
|
+
end
|
158
|
+
# builtin: true
|
159
|
+
# pure: true
|
160
|
+
def sort_by
|
161
|
+
end
|
162
|
+
# builtin: true
|
163
|
+
# pure: true
|
164
|
+
def take(n)
|
165
|
+
end
|
166
|
+
# builtin: true
|
167
|
+
# pure: true
|
168
|
+
def take_while
|
169
|
+
end
|
170
|
+
# builtin: true
|
171
|
+
# pure: true
|
172
|
+
def to_a
|
173
|
+
end
|
174
|
+
# builtin: true
|
175
|
+
# pure: true
|
176
|
+
def zip(ary, *arys)
|
177
|
+
end
|
178
|
+
end
|