Class: Xcplayground::SwiftFile
- Inherits:
-
Object
- Object
- Xcplayground::SwiftFile
- Defined in:
- lib/xcplayground/swift_file.rb
Overview
Represent a Swift language file on disc
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
-
#initialize(filename, content = nil) ⇒ SwiftFile
constructor
A new instance of SwiftFile.
- #save(path) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(filename, content = nil) ⇒ SwiftFile
Returns a new instance of SwiftFile.
7 8 9 10 |
# File 'lib/xcplayground/swift_file.rb', line 7 def initialize(filename, content = nil) @filename = filename @content = content end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/xcplayground/swift_file.rb', line 4 def content @content end |
#filename ⇒ Object
Returns the value of attribute filename.
5 6 7 |
# File 'lib/xcplayground/swift_file.rb', line 5 def filename @filename end |
Instance Method Details
#save(path) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/xcplayground/swift_file.rb', line 12 def save(path) file = File.join(path, filename) File.open(file, 'w') do |f| f.puts to_s end end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/xcplayground/swift_file.rb', line 19 def to_s @content || '//: Playground - noun: a place where people can play' end |