Ruby Quick Reference

Quick reference for efficient coding

View the Project on GitHub YumaYX/RubyQuickReference

text_extract_with_mark_f.rb(ys1)

Extracts lines from the specified file that match the start line pattern and organizes them into ParentAndChild objects.

contents of text_extract_with_mark_f.txt

header1
1
header2
1
2
header3
1
2
3

Execution:

require "ys1"
#=> true

YS1::Text.extract_with_mark_f("text_extract_with_mark_f.txt", /^header/)
#=> 
[#<YS1::ParentAndChild:0x00007f13d0a0dcb0 @children=["1"], @parent="header1">,
 #<YS1::ParentAndChild:0x00007f13d0a0da30
  @children=["1", "2"],
  @parent="header2">,
 #<YS1::ParentAndChild:0x00007f13d0a0d620
  @children=["1", "2", "3", ""],
  @parent="header3">]

Executed with Ruby 3.3.5