Class: Xcplayground::SwiftFile

Inherits:
Object
  • Object
show all
Defined in:
lib/xcplayground/swift_file.rb

Overview

Represent a Swift language file on disc

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/xcplayground/swift_file.rb', line 4

def content
  @content
end

#filenameObject

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_sObject



19
20
21
# File 'lib/xcplayground/swift_file.rb', line 19

def to_s
  @content || '//: Playground - noun: a place where people can play'
end