Created
June 24, 2016 08:16
-
-
Save e-jambon/f2da46ddbef2aadbcdc464b935b6e033 to your computer and use it in GitHub Desktop.
Revisions
-
e-jambon revised this gist
Jun 24, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ def action puts "data = " + data.inspect end def save_to filepath File.open( filepath, 'w+' ) do |f| Marshal.dump(self,f) -
e-jambon created this gist
Jun 24, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ 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