This link has been bookmarked by 12 people . It was first bookmarked on 25 Sep 2007, by swan lin.
-
22 Oct 16
-
Ruby integers are objects of class Fixnum or Bignum
-
The increment and decrement operators (++ and --) are not available in Ruby
-
However, do note that the += and -= are available.
-
-
25 Jan 16
-
- # p002rubynumbers.rb
- =begin
- Ruby Numbers
- Usual operators:
- + addition
- - subtraction
- * multiplication
- / division
- =end
- puts 1 + 2
- puts 2 * 3
- # Integer division
- # When you do arithmetic with integers, you'll get integer answers
- puts 3 / 2
- puts 10 - 11
- puts 1.5 / 2.6
in the digit string. Here's program p002rubynumbers.rb
<!-- InstanceBeginEditable name="Code" --><!-- InstanceEndEditable -->Ruby integers are objects of class Fixnum or Bignum. Th
-
-
02 Jun 14
-
25 Apr 12
-
18 Dec 11
-
18 Nov 11
-
Ruby's definition of the modulo (%) operator differs from that of C and Java. In Ruby, -7%3 is 2. In C and Java, the result is -1 instead. In Ruby, the sign of the result (for % operator) is always the same as the sign of the second operand.
-
-
22 Jun 11
-
17 Apr 11
-
- # When you do arithmetic with integers, you'll get integer answers
-
the sign of the result (for % operator) is always the same as the sign of the second operand.
-
- @variable = @variable || "default value"
- @variable ||= "default value"
A common idiom is to use || to assign a value to a variable only if that variable isn't already set. This can be written as:
<!-- InstanceBeginEditable name="Code" --><!-- InstanceEndEditable -->or, more idiomatically, as:
<!-- InstanceBeginEditable name="Code" -->
-
-
06 Apr 09
-
25 Sep 07
-
Ruby integers are objects of class Fixnum or Bignum. The Fixnum and Bignum classes represent integers of differing sizes. Both classes descend from Integer (and therefore Numeric). The floating-point numbers are objects of class Float, corresponding to the native architecture's double data type.
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.