Tags

커피스크립트 :: join 치환 VIM html function listchars vimrc LCS conceal JavaScript Prototype accessors RUBY pathogen VI 매개변수 Target replaceAll list replace Commonjs nbsp 자바스크립트 Trail Coffeescript SPLIT 루비 arguments

'accessors'에 해당되는 글 1건

  1. 2011/12/01 Ruby, accessors 란?

Ruby, accessorsThe Day of Code

attr_reader, attr_accessor 는 뭘까요?

흥미만 잔뜩 있던, Ruby에 대해서 알고 싶기도 하고, 리팩터링 책도 읽지 못해본 상태라, 두마리 토끼를 잡아보려, "리팩토링:루비 에디션" 을 읽고 있습니다.

그런데 첫 코드에서 막혀 버렸습니다.

나머지는 대충 알겠는데, attr_reader, attr_accessor 요녀석들은 뭘까요?

class Movie
  REGULAR = 0
  NEW_RELEASE =1
  CHILDRENS =2
  
  attr_reader :title
  attr_accessor :price_code
  
  def initialize(title, price_code)
    @title, @price_code = title, price_code
  end
end

Accessors

Yukihiro Matsumoto 님의 Ruby User’s Guide에 쉽게 설명이 있네요.

ShortcutEffect
attr_reader :v def v; @v; end
attr_writer :v def v=(value); @v=value; end
attr_accessor :v attr_reader :v; attr_writer :v
attr_accessor :v, :w attr_accessor :v; attr_accessor :w

Links

저작자 표시 변경 금지
Trackback 0: Comment 0