Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/ruby
File: index.html
<!doctype html>
[0] Fix | Delete
[1] Fix | Delete
<title>CodeMirror: Ruby mode</title>
[2] Fix | Delete
<meta charset="utf-8"/>
[3] Fix | Delete
<link rel=stylesheet href="../../doc/docs.css">
[4] Fix | Delete
[5] Fix | Delete
<link rel="stylesheet" href="../../lib/codemirror.css">
[6] Fix | Delete
<script src="../../lib/codemirror.js"></script>
[7] Fix | Delete
<script src="../../addon/edit/matchbrackets.js"></script>
[8] Fix | Delete
<script src="ruby.js"></script>
[9] Fix | Delete
<style>
[10] Fix | Delete
.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
[11] Fix | Delete
.cm-s-default span.cm-arrow { color: red; }
[12] Fix | Delete
</style>
[13] Fix | Delete
<div id=nav>
[14] Fix | Delete
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
[15] Fix | Delete
[16] Fix | Delete
<ul>
[17] Fix | Delete
<li><a href="../../index.html">Home</a>
[18] Fix | Delete
<li><a href="../../doc/manual.html">Manual</a>
[19] Fix | Delete
<li><a href="https://github.com/codemirror/codemirror">Code</a>
[20] Fix | Delete
</ul>
[21] Fix | Delete
<ul>
[22] Fix | Delete
<li><a href="../index.html">Language modes</a>
[23] Fix | Delete
<li><a class=active href="#">Ruby</a>
[24] Fix | Delete
</ul>
[25] Fix | Delete
</div>
[26] Fix | Delete
[27] Fix | Delete
<article>
[28] Fix | Delete
<h2>Ruby mode</h2>
[29] Fix | Delete
<form><textarea id="code" name="code">
[30] Fix | Delete
# Code from http://sandbox.mc.edu/~bennet/ruby/code/poly_rb.html
[31] Fix | Delete
#
[32] Fix | Delete
# This program evaluates polynomials. It first asks for the coefficients
[33] Fix | Delete
# of a polynomial, which must be entered on one line, highest-order first.
[34] Fix | Delete
# It then requests values of x and will compute the value of the poly for
[35] Fix | Delete
# each x. It will repeatly ask for x values, unless you the user enters
[36] Fix | Delete
# a blank line. It that case, it will ask for another polynomial. If the
[37] Fix | Delete
# user types quit for either input, the program immediately exits.
[38] Fix | Delete
#
[39] Fix | Delete
[40] Fix | Delete
#
[41] Fix | Delete
# Function to evaluate a polynomial at x. The polynomial is given
[42] Fix | Delete
# as a list of coefficients, from the greatest to the least.
[43] Fix | Delete
def polyval(x, coef)
[44] Fix | Delete
sum = 0
[45] Fix | Delete
coef = coef.clone # Don't want to destroy the original
[46] Fix | Delete
while true
[47] Fix | Delete
sum += coef.shift # Add and remove the next coef
[48] Fix | Delete
break if coef.empty? # If no more, done entirely.
[49] Fix | Delete
sum *= x # This happens the right number of times.
[50] Fix | Delete
end
[51] Fix | Delete
return sum
[52] Fix | Delete
end
[53] Fix | Delete
[54] Fix | Delete
#
[55] Fix | Delete
# Function to read a line containing a list of integers and return
[56] Fix | Delete
# them as an array of integers. If the string conversion fails, it
[57] Fix | Delete
# throws TypeError. If the input line is the word 'quit', then it
[58] Fix | Delete
# converts it to an end-of-file exception
[59] Fix | Delete
def readints(prompt)
[60] Fix | Delete
# Read a line
[61] Fix | Delete
print prompt
[62] Fix | Delete
line = readline.chomp
[63] Fix | Delete
raise EOFError.new if line == 'quit' # You can also use a real EOF.
[64] Fix | Delete
[65] Fix | Delete
# Go through each item on the line, converting each one and adding it
[66] Fix | Delete
# to retval.
[67] Fix | Delete
retval = [ ]
[68] Fix | Delete
for str in line.split(/\s+/)
[69] Fix | Delete
if str =~ /^\-?\d+$/
[70] Fix | Delete
retval.push(str.to_i)
[71] Fix | Delete
else
[72] Fix | Delete
raise TypeError.new
[73] Fix | Delete
end
[74] Fix | Delete
end
[75] Fix | Delete
[76] Fix | Delete
return retval
[77] Fix | Delete
end
[78] Fix | Delete
[79] Fix | Delete
#
[80] Fix | Delete
# Take a coeff and an exponent and return the string representation, ignoring
[81] Fix | Delete
# the sign of the coefficient.
[82] Fix | Delete
def term_to_str(coef, exp)
[83] Fix | Delete
ret = ""
[84] Fix | Delete
[85] Fix | Delete
# Show coeff, unless it's 1 or at the right
[86] Fix | Delete
coef = coef.abs
[87] Fix | Delete
ret = coef.to_s unless coef == 1 && exp > 0
[88] Fix | Delete
ret += "x" if exp > 0 # x if exponent not 0
[89] Fix | Delete
ret += "^" + exp.to_s if exp > 1 # ^exponent, if > 1.
[90] Fix | Delete
[91] Fix | Delete
return ret
[92] Fix | Delete
end
[93] Fix | Delete
[94] Fix | Delete
#
[95] Fix | Delete
# Create a string of the polynomial in sort-of-readable form.
[96] Fix | Delete
def polystr(p)
[97] Fix | Delete
# Get the exponent of first coefficient, plus 1.
[98] Fix | Delete
exp = p.length
[99] Fix | Delete
[100] Fix | Delete
# Assign exponents to each term, making pairs of coeff and exponent,
[101] Fix | Delete
# Then get rid of the zero terms.
[102] Fix | Delete
p = (p.map { |c| exp -= 1; [ c, exp ] }).select { |p| p[0] != 0 }
[103] Fix | Delete
[104] Fix | Delete
# If there's nothing left, it's a zero
[105] Fix | Delete
return "0" if p.empty?
[106] Fix | Delete
[107] Fix | Delete
# *** Now p is a non-empty list of [ coef, exponent ] pairs. ***
[108] Fix | Delete
[109] Fix | Delete
# Convert the first term, preceded by a "-" if it's negative.
[110] Fix | Delete
result = (if p[0][0] < 0 then "-" else "" end) + term_to_str(*p[0])
[111] Fix | Delete
[112] Fix | Delete
# Convert the rest of the terms, in each case adding the appropriate
[113] Fix | Delete
# + or - separating them.
[114] Fix | Delete
for term in p[1...p.length]
[115] Fix | Delete
# Add the separator then the rep. of the term.
[116] Fix | Delete
result += (if term[0] < 0 then " - " else " + " end) +
[117] Fix | Delete
term_to_str(*term)
[118] Fix | Delete
end
[119] Fix | Delete
[120] Fix | Delete
return result
[121] Fix | Delete
end
[122] Fix | Delete
[123] Fix | Delete
#
[124] Fix | Delete
# Run until some kind of endfile.
[125] Fix | Delete
begin
[126] Fix | Delete
# Repeat until an exception or quit gets us out.
[127] Fix | Delete
while true
[128] Fix | Delete
# Read a poly until it works. An EOF will except out of the
[129] Fix | Delete
# program.
[130] Fix | Delete
print "\n"
[131] Fix | Delete
begin
[132] Fix | Delete
poly = readints("Enter a polynomial coefficients: ")
[133] Fix | Delete
rescue TypeError
[134] Fix | Delete
print "Try again.\n"
[135] Fix | Delete
retry
[136] Fix | Delete
end
[137] Fix | Delete
break if poly.empty?
[138] Fix | Delete
[139] Fix | Delete
# Read and evaluate x values until the user types a blank line.
[140] Fix | Delete
# Again, an EOF will except out of the pgm.
[141] Fix | Delete
while true
[142] Fix | Delete
# Request an integer.
[143] Fix | Delete
print "Enter x value or blank line: "
[144] Fix | Delete
x = readline.chomp
[145] Fix | Delete
break if x == ''
[146] Fix | Delete
raise EOFError.new if x == 'quit'
[147] Fix | Delete
[148] Fix | Delete
# If it looks bad, let's try again.
[149] Fix | Delete
if x !~ /^\-?\d+$/
[150] Fix | Delete
print "That doesn't look like an integer. Please try again.\n"
[151] Fix | Delete
next
[152] Fix | Delete
end
[153] Fix | Delete
[154] Fix | Delete
# Convert to an integer and print the result.
[155] Fix | Delete
x = x.to_i
[156] Fix | Delete
print "p(x) = ", polystr(poly), "\n"
[157] Fix | Delete
print "p(", x, ") = ", polyval(x, poly), "\n"
[158] Fix | Delete
end
[159] Fix | Delete
end
[160] Fix | Delete
rescue EOFError
[161] Fix | Delete
print "\n=== EOF ===\n"
[162] Fix | Delete
rescue Interrupt, SignalException
[163] Fix | Delete
print "\n=== Interrupted ===\n"
[164] Fix | Delete
else
[165] Fix | Delete
print "--- Bye ---\n"
[166] Fix | Delete
end
[167] Fix | Delete
</textarea></form>
[168] Fix | Delete
<script>
[169] Fix | Delete
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
[170] Fix | Delete
mode: "text/x-ruby",
[171] Fix | Delete
matchBrackets: true,
[172] Fix | Delete
indentUnit: 4
[173] Fix | Delete
});
[174] Fix | Delete
</script>
[175] Fix | Delete
[176] Fix | Delete
<p><strong>MIME types defined:</strong> <code>text/x-ruby</code>.</p>
[177] Fix | Delete
[178] Fix | Delete
<p>Development of the CodeMirror Ruby mode was kindly sponsored
[179] Fix | Delete
by <a href="http://ubalo.com/">Ubalo</a>.</p>
[180] Fix | Delete
[181] Fix | Delete
</article>
[182] Fix | Delete
[183] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function