Skip to content

JoshCheek/DATA.save

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DATA.save

Stored shit in your script's data segment.

Install

$ gem install DATA.save

Example

A program that records how many times it's been run:

require 'DATA.save'

run_count = DATA.load.to_i
run_count += 1
DATA.save run_count

puts "Run count: #{run_count}"

__END__
0

When we invoke it, it increments the counter, which it stores in its DATA segment.

# run it 3 times
$ ruby count_runs.rb
Run count: 1

$ ruby count_runs.rb
Run count: 2

$ ruby count_runs.rb
Run count: 3

# now check out the file
$ cat count_runs.rb
require 'DATA.save'

run_count = DATA.load.to_i
run_count += 1
DATA.save run_count

puts "Run count: #{run_count}"

__END__
3

License

Just do what the fuck you want to.

http://www.wtfpl.net/about/

About

Store shit in your Ruby script's DATA segment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages