diff --git a/test.rb b/test.rb new file mode 100644 index 0000000..e50a861 --- /dev/null +++ b/test.rb @@ -0,0 +1,2 @@ +Created by Satish +Thank God! diff --git a/text.txt b/text.txt new file mode 100644 index 0000000..0a76e1b --- /dev/null +++ b/text.txt @@ -0,0 +1,121 @@ +Among other public buildings in a certain town, which for many +reasons it will be prudent to refrain from mentioning, and to +which I will assign no fictitious name, there is one anciently +common to most towns, great or small: to wit, a workhouse; and +in this workhouse was born; on a day and date which I need not +trouble myself to repeat, inasmuch as it can be of no possible +consequence to the reader, in this stage of the business at all +events; the item of mortality whose name is prefixed to the head +of this chapter. + +For a long time after it was ushered into this world of sorrow +and trouble, by the parish surgeon, it remained a matter of +considerable doubt whether the child would survive to bear any +name at all; in which case it is somewhat more than probable that +these memoirs would never have appeared; or, if they had, that +being comprised within a couple of pages, they would have +possessed the inestimable merit of being the most concise and +faithful specimen of biography, extant in the literature of any +age or country. + +Although I am not disposed to maintain that the being born in a +workhouse, is in itself the most fortunate and enviable +circumstance that can possibly befall a human being, I do mean to +say that in this particular instance, it was the best thing for +Oliver Twist that could by possibility have occurred. The fact +is, that there was considerable difficulty in inducing Oliver to +take upon himself the office of respiration,--a troublesome +practice, but one which custom has rendered necessary to our easy +existence; and for some time he lay gasping on a little flock +mattress, rather unequally poised between this world and the +next: the balance being decidedly in favour of the latter. Now, +if, during this brief period, Oliver had been surrounded by +careful grandmothers, anxious aunts, experienced nurses, and +doctors of profound wisdom, he would most inevitably and +indubitably have been killed in no time. There being nobody by, +however, but a pauper old woman, who was rendered rather misty by +an unwonted allowance of beer; and a parish surgeon who did such +matters by contract; Oliver and Nature fought out the point +between them. The result was, that, after a few struggles, +Oliver breathed, sneezed, and proceeded to advertise to the +inmates of the workhouse the fact of a new burden having been +imposed upon the parish, by setting up as loud a cry as could +reasonably have been expected from a male infant who had not been +possessed of that very useful appendage, a voice, for a much +longer space of time than three minutes and a quarter. + +As Oliver gave this first proof of the free and proper action of +his lungs, the patchwork coverlet which was carelessly flung over +the iron bedstead, rustled; the pale face of a young woman was +raised feebly from the pillow; and a faint voice imperfectly +articulated the words, 'Let me see the child, and die.' + +The surgeon had been sitting with his face turned towards the +fire: giving the palms of his hands a warm and a rub +alternately. As the young woman spoke, he rose, and advancing to +the bed's head, said, with more kindness than might have been +expected of him: + +'Oh, you must not talk about dying yet.' + +'Lor bless her dear heart, no!' interposed the nurse, hastily +depositing in her pocket a green glass bottle, the contents of +which she had been tasting in a corner with evident satisfaction. + +'Lor bless her dear heart, when she has lived as long as I have, +sir, and had thirteen children of her own, and all on 'em dead +except two, and them in the wurkus with me, she'll know better +than to take on in that way, bless her dear heart! Think what it +is to be a mother, there's a dear young lamb do.' + +Apparently this consolatory perspective of a mother's prospects +failed in producing its due effect. The patient shook her head, +and stretched out her hand towards the child. + +The surgeon deposited it in her arms. She imprinted her cold +white lips passionately on its forehead; passed her hands over +her face; gazed wildly round; shuddered; fell back--and died. +They chafed her breast, hands, and temples; but the blood had +stopped forever. They talked of hope and comfort. They had been +strangers too long. + +'It's all over, Mrs. Thingummy!' said the surgeon at last. + +'Ah, poor dear, so it is!' said the nurse, picking up the cork of +the green bottle, which had fallen out on the pillow, as she +stooped to take up the child. 'Poor dear!' + +'You needn't mind sending up to me, if the child cries, nurse,' +said the surgeon, putting on his gloves with great deliberation. +'It's very likely it WILL be troublesome. Give it a little gruel +if it is.' He put on his hat, and, pausing by the bed-side on +his way to the door, added, 'She was a good-looking girl, too; +where did she come from?' + +'She was brought here last night,' replied the old woman, 'by the +overseer's order. She was found lying in the street. She had +walked some distance, for her shoes were worn to pieces; but +where she came from, or where she was going to, nobody knows.' + +The surgeon leaned over the body, and raised the left hand. 'The +old story,' he said, shaking his head: 'no wedding-ring, I see. +Ah! Good-night!' + +The medical gentleman walked away to dinner; and the nurse, +having once more applied herself to the green bottle, sat down on +a low chair before the fire, and proceeded to dress the infant. + +What an excellent example of the power of dress, young Oliver +Twist was! Wrapped in the blanket which had hitherto formed his +only covering, he might have been the child of a nobleman or a +beggar; it would have been hard for the haughtiest stranger to +have assigned him his proper station in society. But now that he +was enveloped in the old calico robes which had grown yellow in +the same service, he was badged and ticketed, and fell into his +place at once--a parish child--the orphan of a workhouse--the +humble, half-starved drudge--to be cuffed and buffeted through +the world--despised by all, and pitied by none. + +Oliver cried lustily. If he could have known that he was an +orphan, left to the tender mercies of church-wardens and +overseers, perhaps he would have cried the louder. \ No newline at end of file diff --git a/text2.txt b/text2.txt new file mode 100644 index 0000000..1810a4b --- /dev/null +++ b/text2.txt @@ -0,0 +1,3 @@ +I love my dog. Go. How are you? + +I love you. \ No newline at end of file diff --git a/tmp.rb b/tmp.rb new file mode 100644 index 0000000..0cc34b8 --- /dev/null +++ b/tmp.rb @@ -0,0 +1,2 @@ +f = ARGV[0] +puts f diff --git a/w2ex3retry.rb b/w2ex3retry.rb new file mode 100644 index 0000000..a290fa0 --- /dev/null +++ b/w2ex3retry.rb @@ -0,0 +1,33 @@ +def leap_year(year) + if year%4==0 + if year%100==0 + if year%400==0 + leap_year = true + else + leap_year = false + end + else + leap_year = true + end + else + leap_year = false + end + if leap_year == true + yield(366*24*60, leap_year) + else + yield(365*24*60, leap_year) + end +end +puts"Enter a year and I will tell you if it's a leap year" +print"? " +STDOUT.flush +year = gets.to_i +leap_year(year) {|minutes, leap_year| + if leap_year == true + puts "#{year} is a leap year." + puts "There are #{minutes} minutes in a leap year." + else + puts "#{year} is not a leap year" + puts "There are #{minutes} minutes in a non leap year." + end +} \ No newline at end of file diff --git a/w3ex10.rb b/w3ex10.rb new file mode 100644 index 0000000..61af839 --- /dev/null +++ b/w3ex10.rb @@ -0,0 +1,7 @@ +collection = [1,2,3,4,5] +sum = 0 +collection.each do |x| + sum += x +end + +puts sum \ No newline at end of file diff --git a/w3ex2.rb b/w3ex2.rb new file mode 100644 index 0000000..2485d37 --- /dev/null +++ b/w3ex2.rb @@ -0,0 +1,19 @@ +print "Enter the file to be evaluated: > " +file = gets.chomp + +replacement_file = "" + +File.open(file, 'r') do |f| + while line = f.gets + line["word"] = "inserted word" if line.include?("word") + replacement_file << line + end +end + +File.open(file, 'w') do |f| + f.puts replacement_file +end + + + + \ No newline at end of file diff --git a/w3ex3.rb b/w3ex3.rb new file mode 100644 index 0000000..eb2a043 --- /dev/null +++ b/w3ex3.rb @@ -0,0 +1,19 @@ +#Displays the current working directory +original_directory = Dir.getwd +puts original_directory + +#Creates new directory called tmp +Dir.mkdir('tmp') + +#Changes the directory to tmp +Dir.chdir('tmp') + +#Displays the current working directory +puts Dir.getwd + +#goes back to original wprking directory +Dir.chdir(original_directory) +puts Dir.getwd + +#delete the tmp directory +Dir.delete('tmp') diff --git a/w3ex5.rb b/w3ex5.rb new file mode 100644 index 0000000..f4587de --- /dev/null +++ b/w3ex5.rb @@ -0,0 +1,5 @@ + +s = 'key=value' +s1, s2 = s.split('=') +puts s1 +puts s2 diff --git a/w3ex6.rb b/w3ex6.rb new file mode 100644 index 0000000..f5fc28f --- /dev/null +++ b/w3ex6.rb @@ -0,0 +1,16 @@ + +you_say = "" + +until you_say == "BYE" + + print "You say to Grandma > " + you_say = gets.chomp + + if you_say != you_say.upcase + puts "HUH?! SPEAK UP, SONNY" + elsif you_say != "BYE" + puts "NO, NOT SINCE #{rand(1938...1950)}" + end +end + +puts "Grandma walks away." diff --git a/w3ex7.rb b/w3ex7.rb new file mode 100644 index 0000000..e92c7e6 --- /dev/null +++ b/w3ex7.rb @@ -0,0 +1,33 @@ +line_count = 0 + +File.open('text.txt') do |f| + while line = f.gets + line_count += 1 + end +end + + +new_file = File.read('text.txt') +puts new_file.class + +character_count = new_file.scan(/./).size +character_count_wo_spaces = (character_count) - (new_file.count " ") + +word_count = new_file.scan(/\w+/).size +sentence_count = new_file.scan(/((?<=[a-z0-9)][.?!])|(?<=[a-z0-9][.?!]"))\s+(?="?[A-Z])/).size +paragraph_count = new_file.scan(/\n\n/).size + +average_num_words_per_sentence = word_count.to_f / sentence_count +average_num_sentences_per_paragraph = sentence_count.to_f / paragraph_count + +puts "There are #{character_count} characters in the file" +puts "There are #{character_count_wo_spaces} characters not including spaces in the file" +puts "There are #{line_count} lines in the file" +puts "There are #{word_count} words in the file" +puts "There are #{sentence_count} sentences in the file" +puts "There are #{paragraph_count} paragraphs in the file" +puts "There are an average of #{average_num_words_per_sentence} words per sentence in the file" +puts "There are an average of #{average_num_sentences_per_paragraph} sentences per paragraph in the file" + + + diff --git a/w3ex8.rb b/w3ex8.rb new file mode 100644 index 0000000..96536d8 --- /dev/null +++ b/w3ex8.rb @@ -0,0 +1,9 @@ +(1..100).each do |count| + output = "" + output = "Fizz" if count % 3 == 0 + output += "Buzz" if count % 5 == 0 + output = count if output == "" + + puts output + +end \ No newline at end of file diff --git a/w3ex9.rb b/w3ex9.rb new file mode 100644 index 0000000..34344d6 --- /dev/null +++ b/w3ex9.rb @@ -0,0 +1,15 @@ +def reverse_string_word_order(string) + words = [] + words << string.split(" ") + reverse_string = "" + words[0].reverse_each { |x| reverse_string<< x + " "} + yield(reverse_string) + +end + +print "Enter a string: > " +STDOUT.flush +string = gets.chomp + +reverse_string_word_order(string){|reverse_string| puts reverse_string} + diff --git a/word.txt b/word.txt new file mode 100644 index 0000000..ea6ced6 --- /dev/null +++ b/word.txt @@ -0,0 +1,14 @@ +test test test test test +test test test test test +test test test test test +test test test test test +test test test test test +test test inserted inserted word test test +test test test test test +test test test test test +test test test test test +test test test test test + +test test test test test2 + +hello \ No newline at end of file