Ruby/Справочник/Fixnum: различия между версиями

Содержимое удалено Содержимое добавлено
Нет описания правки
Нет описания правки
Строка 21:
===Fixnum::induced_from===
----
<source <ttlang=ruby>Fixnum.induced_from(obj) =&gt;#-> fixnum</ttsource>
----
Convert <tt>obj</tt> to a Fixnum. Works with numeric parameters. Also works with Symbols, but this is deprecated.
===Fixnum#%===
----
<source <ttlang=ruby>fix % other =&gt;#-> Numeric
fix.modulo(other) =&gt;#-> Numeric</ttsource>
----
Returns <tt>fix</tt> modulo <tt>other</tt>. See <tt>Numeric.divmod</tt> for more information.
===Fixnum#&===
----
<source <ttlang=ruby>fix &amp; other =&gt;#-> integer</ttsource>
----
Bitwise AND.
===Fixnum#*===
----
<source <ttlang=ruby>fix * numeric =&gt;#-> numeric_result</ttsource>
----
Performs multiplication: the class of the resulting object depends on the class of <tt>numeric</tt> and on the magnitude of the result.
===Fixnum#**===
----
<source <ttlang=ruby>**(other)</ttsource>
----
Alias for #rpower
===Fixnum#+===
----
<source <ttlang=ruby>fix + numeric =&gt;#-> numeric_result</ttsource>
----
Performs addition: the class of the resulting object depends on the class of <tt>numeric</tt> and on the magnitude of the result.
===Fixnum#-===
----
<ttsource lang=ruby>fix - numeric =&gt;#-> numeric_result</ttsource>
----
Performs subtraction: the class of the resulting object depends on the class of <tt>numeric</tt> and on the magnitude of the result.
===Fixnum#-@===
----
<ttsource lang=ruby>-fix =&gt;#-> integer</ttsource>
----
Negates <tt>fix</tt> (which might return a Bignum).
===Fixnum#/===
----
<source <ttlang=ruby>fix / numeric =&gt;#-> numeric_result
fix.div(numeric) #-> =&gt; </tt><tt>numeric_result</ttsource>
----
Performs division: the class of the resulting object depends on the class of <tt>numeric</tt> and on the magnitude of the result.
===Fixnum#<===
----
<ttsource lang=ruby>fix &lt;< other =&gt;#-> true or false</ttsource>
----
Returns <tt>true</tt> if the value of <tt>fix</tt> is less than that of <tt>other</tt>.
===Fixnum#<<===
----
<ttsource lang=ruby>fix &lt;&lt;<< count =&gt;#-> integer</ttsource>
----
Shifts <i>fix</i> left <i>count</i> positions (right if <i>count</i> is negative).
===Fixnum#<====
----
<ttsource lang=ruby>fix &lt;<= other =&gt;#-> true or false</ttsource>
----
Returns <tt>true</tt> if the value of <tt>fix</tt> is less thanor equal to that of <tt>other</tt>.
===Fixnum#<=>===
----
<ttsource lang=ruby>fix &lt;<=&gt;> numeric =&gt;#-> -1, 0, +1</ttsource>
----
Comparison---Returns -1, 0, or +1 depending on whether <i>fix</i> is less than, equal to, or greater than <i>numeric</i>. This is the basis for the tests in <tt>Comparable</tt>.
===Fixnum#=====
----
<ttsource lang=ruby>fix == other</ttsource>
----
Return <tt>true</tt> if <tt>fix</tt> equals <tt>other</tt> numerically.
<source <codelang=ruby>1 == 2 #=&gt; false
1 == 1.0 #=-> true</codesource>
===Fixnum#>===
----
<ttsource lang=ruby>fix &gt;> other =&gt;#-> true or false</ttsource>
----
Returns <tt>true</tt> if the value of <tt>fix</tt> is greater than that of <tt>other</tt>.
===Fixnum#>====
----
<ttsource lang=ruby>fix &gt;>= other =&gt;#-> true or false</ttsource>
----
Returns <tt>true</tt> if the value of <tt>fix</tt> is greater than or equal to that of <tt>other</tt>.
===Fixnum#>>===
----
<ttsource lang=ruby>fix &gt;&gt;>> count =&gt;#-> integer</ttsource>
----
Shifts <i>fix</i> right <i>count</i> positions (left if <i>count</i> is negative).
===Fixnum#[]===
----
<source <ttlang=ruby>fix[n] =&gt;#-> 0, 1</ttsource>
----
Bit Reference---Returns the <i>n</i>th bit in the binary representation of <i>fix</i>, where <i>fix</i>[0] is the least significant bit.
<source <codelang=ruby>a = 0b11001100101010
30.downto(0) do |n| print a[n] end</codesource>
''результат'':
<i>produces:</i>
<codett>0000000000000000011001100101010</codett>
===Fixnum#^===
----
<source <ttlang=ruby>fix ^ other =&gt;#-> integer</ttsource>
----
Bitwise EXCLUSIVE OR.
===Fixnum#abs===
----
<ttsource lang=ruby>fix.abs #-&gt;> aFixnum</ttsource>
----
Returns the absolute value of <i>fix</i>.
<codesource lang=ruby>-12345.abs #=&gt;-> 12345
12345.abs #=-> 12345</codesource>
===Fixnum#div===
----
<source <ttlang=ruby>fix / numeric =&gt;#-> numeric_result
fix.div(numeric) #-> =&gt; </tt><tt>numeric_result</ttsource>
----
Performs division: the class of the resulting object depends on the class of <tt>numeric</tt> and on the magnitude of the result.
===Fixnum#divmod===
----
<source <ttlang=ruby>fix.divmod(numeric) =&gt;#-> array</ttsource>
----
See <tt>Numeric#divmod</tt>.
===Fixnum#id2name===
----
<ttsource lang=ruby>fix.id2name #-&gt;> string or nil</ttsource>
----
Returns the name of the object whose symbol id is <i>fix</i>. If there is no symbol in the symbol table with this value, returns <tt>nil</tt>. <tt>id2name</tt> has nothing to do with the <tt>Object.id</tt> method. See also <tt>Fixnum#to_sym</tt>, <tt>String#intern</tt>, and class <tt>Symbol</tt>.
<source <codelang=ruby>symbol = :@inst_var #=&gt;-> :@inst_var
id = symbol.to_i #=-> 9818
id.id2name #=-> "@inst_var"</codesource>
===Fixnum#modulo===
----
<source <ttlang=ruby>fix % other =&gt;#-> Numeric
fix.modulo(other) =&gt;#-> Numeric</ttsource>
----
Returns <tt>fix</tt> modulo <tt>other</tt>. See <tt>Numeric.divmod</tt> for more information.
===Fixnum#power!===
----
<source <ttlang=ruby>power!(p1)</ttsource>
----
Alias for #**
===Fixnum#quo===
----
<source <ttlang=ruby>fix.quo(numeric) =&gt;#-> float</ttsource>
----
Returns the floating point result of dividing <i>fix</i> by <i>numeric</i>.
<source <codelang=ruby>654321.quo(13731) #=&gt;-> 47.6528293642124
654321.quo(13731.24) #=-> 47.6519964693647</codesource>
 
(еще известен как /, rdiv)
===Fixnum#rdiv===
----
<source <ttlang=ruby>rdiv(p1)</ttsource>
----
Alias for #quo
===Fixnum#rpower===
----
<source <ttlang=ruby>rpower(other)</ttsource>
----
Returns a Rational number if the result is in fact rational (i.e. <tt>other</tt> &lt; 0).
Строка 182:
===Fixnum#size===
----
<ttsource lang=ruby>fix.size #-&gt;> fixnum</ttsource>
----
Returns the number of <i>bytes</i> in the machine representation of a <tt>Fixnum</tt>.
<source <codelang=ruby>1.size #=&gt;-> 4
-1.size #=-> 4
2147483647.size #=-> 4</codesource>
===Fixnum#to_f===
----
<source <ttlang=ruby>fix.to_f #-&gt;> float</ttsource>
----
Converts <i>fix</i> to a <tt>Float</tt>.
===Fixnum#to_s===
----
<ttsource lang=ruby>fix.to_s( base=10 ) #-&gt;> aString</ttsource>
----
Returns a string containing the representation of <i>fix</i> radix <i>base</i> (between 2 and 36).
<source <codelang=ruby>12345.to_s #=&gt;-> &quot;"12345&quot;"
12345.to_s(2) #=-> "11000000111001"
12345.to_s(8) #=-> "30071"
12345.to_s(10) #=-> "12345"
12345.to_s(16) #=-> "3039"
12345.to_s(36) #=-> "9ix"</codesource>
===Fixnum#to_sym===
----
<source <ttlang=ruby>fix.to_sym #-&gt;> aSymbol</ttsource>
----
Returns the symbol whose integer value is <i>fix</i>. See also <tt>Fixnum#id2name</tt>.
<code>fred = :fred.to_i
fred.id2name #=-> "fred"
fred.to_sym #=-> :fred</code>
===Fixnum#xchr===
----
<source <ttlang=ruby>xchr()</ttsource>
----
XML escaped version of chr
===Fixnum#zero?===
----
<source <ttlang=ruby>fix.zero? =&gt;#-> true or false</ttsource>
----
Returns <tt>true</tt> if <i>fix</i> is zero.
===Fixnum#|===
----
<source <ttlang=ruby>fix | other =&gt;#-> integer</ttsource>
----
Bitwise OR.
===Fixnum#~===
----
<source <ttlang=ruby>~fix =&gt;#-> integer</ttsource>
----
One's complement: returns a number where each bit is flipped.