Created
June 24, 2016 08:16
-
-
Save e-jambon/f2da46ddbef2aadbcdc464b935b6e033 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ItemMenu = Struct.new(:lvl, :description, :command_type, :data) do | |
def action | |
puts "data = " + data.inspect | |
end | |
def save_to filepath | |
File.open( filepath, 'w+' ) do |f| | |
Marshal.dump(self,f) | |
end | |
end | |
def load_from filepath | |
File.open(filepath, 'r') do |f| | |
tmp = Marshal.load(f) | |
puts "tmp : " + tmp.inspect | |
self.lvl = tmp.lvl | |
self.description = tmp.description | |
self.command_type = tmp.command_type | |
self.data = tmp.data | |
end | |
end | |
end | |
l_1 = ItemMenu.new( '0.1', 'First Item','shell', 'ls' ) | |
puts ' == CREATION == ' | |
puts l_1.lvl | |
puts l_1.description | |
puts l_1.command_type | |
puts l_1.data | |
puts l_1.action | |
puts ' == SAVING == ' | |
l_1.save_to '/home/username/work/menu/data/l_1.txt' | |
puts '== LOADING == ' | |
l_2 = ItemMenu.new | |
l_2.load_from '/home/username/work/menu/data/l_1.txt' | |
puts l_2.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment