czwartek, 16 czerwca 2011

Lepsze wsparcie dla YARD w nowym RubyMine (3.2)

Dobrze jest pisać komentarze i dokumentować kod - to wie każdy. Nowoczesne IDE potrafią dzięki dobrze zbudowanej dokumentacji lepiej podpowiadać kod (potrzebne parametry i ich typ, typ zwróconej wartości itd.)

Nowa wersja RubyMine (3.2) wprowadza lepszy support dla YARD. Sprawa jest generalnie prosta. Piszemy odpowiednio komentarze nad kodem używając składni YARD:

# User model used for authentication.
# Uses 3.1's has_secure_password
#
# == Schema information
# Table name: users
#
# id :integer not null, primary key
# username :string(150)
# email :string(150)
# password_digest :string
# created_at :datetime
# updated_at :datetime
#
# Meta field (for authentication)
# password :string
# password_confirmation :string
#
# @author Krzysztof Zalewski [zlw.zalewski@gmail.com]
#
class User < ActiveRecord::Base
# some code here...
# Returns public information about User
#
# @example Returns profile
# User.find(1).get_profile #=> { :id=>1, :username=>"spiderman", (...) }
#
# @return [Hash]
#
def get_profile
@profile ||= { id: id, username: username, email: email,
created_at: created_at, updated_at: updated_at }
end
end
view raw user.rb hosted with ❤ by GitHub

Dzięki czemu uzyskujemy lepsze podpowiedzi:


Brak komentarzy:

Prześlij komentarz