This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
notes: I need to use readlines method....also I need to make a method that accepts user input or accepts a directory as an arg and maybe includes input validation to make sure that the directory includes "' '" or maybe easier include the single quotes in the method... | |
end | |
read_source_lines_from_file_to_a = File.read('C:\Users\demon002\text.txt').each_line.to_a | |
read_source_lines_from_file_to_a[5] = "test test inserted word test test" | |
File.open('C:\Users\demon002\text.txt', "w") do |inst| | |
inst.puts read_source_lines_from_file_to_a.to_s | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a little program to accept a list of words, sort them without using the sort method, and output them in alphabetical order | |
i, j = 0, 0 # initialization of index variables | |
words, words2 = [], [] | |
a_word = 'a' # dummy initialization to get into the until loop below | |
puts "Type a word and press <Enter> (Enter a blank line to quit):" | |
# Loop to accept an unspecified number of words-- creates original array | |
until a_word.empty? | |
a_word = gets.chomp | |
unless a_word.empty? | |
words.push a_word |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
doctest: leap_year? for 1900 and 1999 and 2001 is false | |
>> leap_year?(1900) | |
=> false | |
>> leap_year?(1999) | |
=> false | |
>> leap_year?(2001) | |
=> false | |
doctest: leap_year? for 1904, 1996 and 2000 are true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# require FileUtils | |
require 'fileutils' | |
FileUtils.mv 'test.txt', 'test1.txt' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SyntaxError: compile error | |
(irb):3: syntax error, unexpected kNOT, expecting ')' | |
puts( not(1 == 1)) | |
^ | |
(irb):3: syntax error, unexpected ')', expecting $end | |
from (irb):3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> puts (not(1 == 1)) | |
false | |
=> nil | |
>> puts( not(1 == 1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SyntaxError: compile error | |
(irb):1: syntax error, unexpected kNOT, expecting $end | |
puts not(1 == 1) | |
^ | |
from (irb):1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts (not(1 == 1) ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts( not( 1 == 1) ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts( not(1 == 1) ) |