#Ruby Programming Language
#Chapter 7 Classes and Modules
- Keywords to define class:
def
,class
- Class constructor can be defined with
def initialize
example of Point class:
struct MaxHeap<T: Comparable>: CustomStringConvertible { | |
var heap: [T] = [] | |
var size: Int { | |
return heap.count | |
} | |
var description: String { | |
return "\(heap)" | |
} | |
extension String { | |
subscript(idx: Int) -> Character { | |
let i = index(startIndex, offsetBy: idx) | |
return self[i] | |
} | |
subscript(range: CountableRange<Int>) -> String { | |
let s = index(startIndex, offsetBy: range.lowerBound) | |
let e = index(startIndex, offsetBy: range.upperBound) | |
return String(self[s..<e]) |
git diff origin/master --name-only | grep '\.swift' | xargs -I _path swiftlint --path "./_path" |
#Ruby Programming Language
#Chapter 6 Methods, Procs, Lambdas, and Closures
##Defining methods
def
followed by method name#!/usr/bin/ruby | |
require 'find' | |
funcHash = Hash.new | |
functions = Array.new | |
files = Array.new | |
Dir.glob("**/*") { |path| | |
swift_file = path if path =~ /.*\.swift$/ |
extension UIColor { | |
class func random() -> UIColor { | |
let randomRed:CGFloat = CGFloat(drand48()) | |
let randomGreen:CGFloat = CGFloat(drand48()) | |
let randomBlue:CGFloat = CGFloat(drand48()) | |
return UIColor(red: randomRed, green: randomGreen, | |
blue: randomBlue, alpha: 1.0) |
extension NSURL { | |
func query(parameter forKey:String, separator: String) -> String? { | |
return query?.components(separatedBy: | |
CharacterSet(charactersIn: separator)).first(where: { | |
$0.removingPercentEncoding?.hasPrefix(forKey) == true | |
})?.replacingOccurrences(of: forKey, with: "") | |
} | |
} | |
let url = NSURL(string: "https://www.google.pl/?gfe_rd=cr&ei=zjCGWJ33OsTi8Aef1qf4Cg") |