fork download
  1. # http://stackoverflow.com/q/38628521/5290909
  2.  
  3. regex = /^
  4. (\s*) # matches the indentation (we'll backreference later)
  5. def\ +has_many\b # literal "def has_many" with a word boundary
  6. (?:.*+\n)*? # match whole lines - as few as possible
  7. \1 # matches the same indentation as the def line
  8. end\b # literal "end"
  9. /x
  10.  
  11. subject = %q|
  12. def has_many(name, scope = nil, options = {}, &extension)
  13. if association.nil?
  14. instance_variable_set("@#{association_name}", association)
  15. end
  16. end|
  17.  
  18.  
  19. #Print matched text
  20. puts subject.to_enum(:scan,regex).map {$&}
Success #stdin #stdout 0.05s 9648KB
stdin
Standard input is empty
stdout
  def has_many(name, scope = nil, options = {}, &extension)
      if association.nil?
        instance_variable_set("@#{association_name}", association)
      end
  end