看板 [ Ruby ]
討論串[問題] 相同的instance和class method
共 4 篇文章
首頁
上一頁
1
下一頁
尾頁

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者ryudo (那很好哇)時間15年前 (2010/05/13 00:53), 編輯資訊
0
0
0
內容預覽:
應該使用module. module Abc. def methoda. ...... end. end. class Xxxxx. include Abc. extend Abc. end. 這樣Xxxxx.methoda和Xxxxx.new.methoda 基本上就是等效了. --. 發信站

推噓1(1推 0噓 0→)留言1則,0人參與, 最新作者godfat (godfat 真常)時間15年前 (2010/05/11 18:04), 編輯資訊
0
0
4
內容預覽:
[...]. 我在 facebooker 裡面看到不少類似的用法,這讓我感到很混淆,. 因為我會搞不清楚當我看到 Item.price 和 Item.new.price 之間的差別是什麼?. 翻了 source code 之後才發現其實根本一樣。. 我覺得所謂 instance method, 就是
(還有649個字)

推噓4(4推 0噓 1→)留言5則,0人參與, 最新作者ihower (好2ˇ)時間15年前 (2010/05/10 17:22), 編輯資訊
0
0
0
內容預覽:
是指 instance method 跟 class method 一樣嗎? XD. def price. self.class.price. end. def self.price. .... end. --. 發信站: 批踢踢實業坊(ptt.cc). ◆ From: 114.43.194.2

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者bypang (甚麼時候才等到妳)時間15年前 (2010/05/10 15:32), 編輯資訊
0
0
0
內容預覽:
如果有相同結構的instance和class method,要如何做才能dry呢?. class Product < ActiveRecord::Base. def price. .... end. def self.price. .... end. end. class ProductsContr
(還有8個字)
首頁
上一頁
1
下一頁
尾頁