April 7, 2011

Fix num documentation


Modulus
Puts 5%3 gives you the reminder.
Result =2.
Puts 3&5
&- Binary and operator 3-011 & 5-101
Result = 1-001
Puts 5*3 gives product values 15
** puts 5**3 result will be power values 5^3=125
+ for addition
-For Subraction
-@ negative fix
/ for division
< for less than
<< for shift fix left register location puts 2<<1
Then 2=0010 shift register 0100 result is 4
Puts 5<<2, 5=101 result 10100=20
>> for shift fix right register location puts 2<<1
Then 2=0010 shift register 0001 result is 1
Puts 5>>1, 5=0101 result 0010=2
__id__  => This helps you shift register bits. Puts 5.__id__ => 11 & puts 3.__id__ => 7
 In the above example 5=0101 for 11=>1011 in the above example, add a bit “1” at the end. Then the value changes to 11 for 5.

<=    puts 3<=5 => true   &   <=     puts 5<=3 => false
<=>puts 5 <=> 3 => 1 & puts 5 <=> 5 => 0 & puts 5 <=> 7 => -1
== provides equal values puts 5==3 => false & puts 5==5 => true
===  puts 5===3 => false & puts 5===5 => true
=~  This is for Pattern matching (Pattern Match—Overridden by descendents (notably Regexp and String) to provide meaningful pattern-match semantics.)
>   greater than symbol puts 5>3 => true puts 3>5 => False which is similar to >= symbol also
[]  Bit Reference—Returns the nth bit in the binary representation of fix, where fix[0] is the least significant bit.
^ puts 5^3 => 6Bitwise EXCLUSIVE OR.  5= 0101 + 3=0011 then make Or operation add 1 for the output.
_ _send_     => class Klass   def hello(*args)   “Hello ” + args.join(‘ ‘) end  end
k = Klass.new k.send :hello, “gentle”, “readers” #=> “Hello gentle readers”
abs puts 5.abs => 5   puts -5.abs => 5  It gives the value without consider about plus or minus
between?    puts 5.between?(3,8) => true,,  puts 5.between?(3,4) => false,, 5 is placed between 3 to 8,   5 is not placed in between 3 to 4.

.eql?  1 == 1.0 #=> true, 1.eql?(1.0) #=> false, (1.0).eql?(1.0) #=> true     Returns true if num and numeric are the same type and have equal values.
Extend one module with another module
Floor
String: Changing a section of string.
A= “Puts jegan”……. a.gsub(“jeg”, “Raj”)………….result => a=> “Puts Rajan”
String for the delimiter can be used as
A= “asdfASDF” or A=%{asdfasdfas} or a=<<JEG asdfasdf JEG
myString = "Welcome to PHP Essentials!"
=> "Welcome to PHP Essentials!"
myString.gsub("PHP", "Ruby")
=> "Welcome to Ruby Essentials!"
myString.replace "Goodbye to PHP!"
=> "Goodbye to PHP!"

No comments:

Post a Comment