4
String 클래스에 추가 메서드를 추가했습니다. 나중에이 메서드를 사용하고 싶지만 메서드가 잘못되었습니다.Rubymotion : 메서드 추가시 NoMethodError
class String
def as_file_full_path
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true) [0].stringByAppendingPathComponent(self)
end
end
나는 그것이 작동 REPL에서 다음을하려고하면 더 이상
(main)> "image.jpg".as_full_path
=> "/Users/user/Library/Application Support/iPhone Simulator/6.1/Applications/30D186A9-B1C7-4377-AE91-0D14BD3B4A6D/Documents/image.jpg"
하지만 내 모델 클래스의 메소드를 호출 할 때, 그것은 작동하지 않습니다
(main)> w = Word.first
=> #<Word:0x94d7df0>
(main)> w.filename
=> "2C86A58A-A92A-4A0F-B26C-0F5F583E142C.caf"
(main)> w.filename.class
=> String
(main)> w.filename.as_full_path
2013-02-28 09:17:55.935 project[74283:c07] undefined method `as_full_path' for "2C86A58A-A92A-4A0F-B26C-0F5F583E142C.caf":String (NoMethodError)
=> NoMethodError: undefined method `as_full_path' for "2C86A58A-A92A-4A0F-B26C-0F5F583E142C.caf":String
모델은 NanoStore :: Model을 사용하여 구현됩니다.
편집 : 나는 모델에 의해 반환 된 문자열을 복제 할 때, 추가 방법 이 현재는
입니다.
w.filename.dup.as_full_path
=> "/Users/user/Library/Application Support/iPhone Simulator/6.1/Applications/30D186A9-B1C7-4377-AE91-0D14BD3B4A6D/Documents/2C86A58A-A92A-4A0F-B26C-0F5F583E142C.caf"