Uncategorized
Ruby, Testing
In Ruby -> Test::unit::TestCase is easy
require ‘test/unit’
the name of the class to be tested is Roman then the testing class will TestRoman < Test::Unit::TestCase
and a simple method
def test_simple
assert_equal (“expected_result”, call_to the method of class to be checked –>actual result)
end
for testing a particular method….
ruby test_roman.rb –name “name of the method”
location of the test file should
$:.unshift File.join(File.dirname(__FILE__),”..”,”lib”)
require….the [...]
Ruby – Numeric
Numeric
Integer Float
FixNum BigNum Rational ComplexNum
nan?
zero?/nonzero?
finite?/infinite?,integer?
ceil,floor,round,
divmod,quo,remainder
next,succ,step(10,2),times,chr,
ruby rake
ruby is make like utility.Make utility makes a install with all the options and config you want .Rake is similar to Make
within a rails application go to that directory ask the rake to tell about itself
rake -T
rake rails:freeze:gems
rake doc:rails : will install the rdoc for the rails –> the activerecord#find etc…in the html format in [...]
Ruby : Math
Math is a module which has a lot of useful Methods.
To convert from one class to another just call the class name followed by parameter.
Integer(field)
Float(field)
String(field)
All other method are applied on the object itself like 3.div 3 or 12.divmod 5 which divides and gives the balance. or you can remainder to get the remainder alone.
you [...]
rails basics
render(:controller=>’say’ ,:action=>’hello’)
render(:partial => ‘form’)
redirect(:controller=>’say’ :action=>’hello’)
link_to(‘mylink’,:controller= >’say’,:action=>’hello’,:id=>1)
params.inspect
logger.warn,logger.error,logger.info,logger.fatal
(ActionView only) debug(params)
( FormHelpers only)
<input type =’text’ name=album[title]/> can be written as
<%= form_tag(:action=>’create’) do %>
<%= text_field(:album, :title) %>
<%= datetime_select(:album, :release_date) %>
<%= submit_tag(“name of button”) %>
<%= end %>
form_tag
form
error_messages_for(:album) —> debug(album.errors)
validates_presence_of :artist
before_filter(controller) :method nly/:except =>[]
after_filter(controller) :method nly
Model inherits from ActiveRecord::Base which has methods like find,find_by_id,find_by_sql,save,update,destroy
Controller is inherited [...]
ruby gems
http://docs.rubygems.org/read/book/2
gem -v : would give the version
gem list –local : list of all gems in the system with thier version number.if there was 2 version then it would give them in descending order
gem outdated : would give list of gems which are outdate
gem update : would update all the gems.
gem update –include-dependencies –no-rdoc
gem cleanup : [...]
$0 , __FILE__
$0 is the file which load any other ruby file which is contained in __FILE__….
Read Full Post | Make a Comment ( None so far )Splat Operator in Ruby
* is called the splat operator in ruby .The first time you come across is for variable argument.that is exactly what you will be using it for.it should be used as the last argument.
name,*rest_of_address = address[]
would put the first argument to name and rest to the * argument…
THe other thing about it is it gives [...]
Structures in Ruby
If you wanted just a storage variable in terms of big structure with no code on them .The best way is to call Struct.new followed by what ever structure fields you want on them.Once the structure is created you can create a new on it by just calling the name of the Structure .new [...]
Read Full Post | Make a Comment ( None so far )Ruby – Date/Time
Time.now : will give the time now…
%a – The abbreviated weekday name (“Sun”)
%A – The full weekday name (“Sunday”)
%b – The abbreviated month name (“Jan”)
%B – The full month name (“January”)
%c – The preferred local date and time representation
%d – Day of the month (01..31)
%H – Hour of the day, 24-hour clock (00..23)
%I – [...]
« Previous Entries