Module: Chozo::Mixin::FromFile
- Defined in:
- lib/chozo/mixin/from_file.rb
Overview
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#class_from_file(filename) ⇒ Object
Loads the contents of a file within the context of the current object’s class.
-
#from_file(filename) ⇒ Object
Loads the contents of a file within the context of the current object.
Class Method Details
.included(base) ⇒ Object
15 16 17 |
# File 'lib/chozo/mixin/from_file.rb', line 15 def included(base) base.extend(ClassMethods) end |
Instance Method Details
#class_from_file(filename) ⇒ Object
Loads the contents of a file within the context of the current object’s class
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/chozo/mixin/from_file.rb', line 43 def class_from_file(filename) filename = filename.to_s if File.exists?(filename) && File.readable?(filename) self.class_eval(IO.read(filename), filename, 1) self else raise IOError, "Could not open or read: '#{filename}'" end end |
#from_file(filename) ⇒ Object
Loads the contents of a file within the context of the current object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chozo/mixin/from_file.rb', line 26 def from_file(filename) filename = filename.to_s if File.exists?(filename) && File.readable?(filename) self.instance_eval(IO.read(filename), filename, 1) self else raise IOError, "Could not open or read: '#{filename}'" end end |