story_with_ruby 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/bin/active-record.rb +52 -0
- data/bin/strings_and_arrays.rb +149 -0
- data/lib/story_with_ruby/version.rb +1 -1
- data/story_with_ruby.gemspec +1 -1
- metadata +7 -4
data/.gitignore
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
#twiking irb: http://stackoverflow.com/questions/123494/whats-your-favourite-irb-trick
|
6
|
+
#http://www.tutorialspoint.com/ruby-on-rails/rails-callback-functions.htm
|
7
|
+
#
|
8
|
+
#
|
9
|
+
#http://www.tutorialspoint.com/ruby/ruby_exceptions.htm
|
10
|
+
#all event option
|
11
|
+
#http://apir.rubyonrails.org/
|
12
|
+
#life cycle of rest object: `http://api.rubyonrails.org/classes/ActiveResource/Base.html
|
13
|
+
#
|
14
|
+
#
|
15
|
+
#
|
16
|
+
puts 'in the absolute beginning of life there was nothing .. just a potential..'
|
17
|
+
class Monkey < ActiveRecord::Base
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
begin
|
22
|
+
puts "and god said: let there be light"
|
23
|
+
#raise Exception, "but no light!"
|
24
|
+
|
25
|
+
c1 = Monkey.new
|
26
|
+
|
27
|
+
rescue Exception => e
|
28
|
+
puts e.message
|
29
|
+
(e.methods - Object.new.methods).to_json #ommit derived methods
|
30
|
+
else
|
31
|
+
puts "Congratulations-- no errors!"
|
32
|
+
ensure
|
33
|
+
puts "but no light!"
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
class Person < ActiveRecord::Base
|
40
|
+
establish_connection :adapter => 'sqlite3', :database => 'foobar.db'
|
41
|
+
connection.create_table table_name, :force => true do |t|
|
42
|
+
t.string :name
|
43
|
+
end
|
44
|
+
end
|
45
|
+
bob= Person.new(:name => 'bob')
|
46
|
+
bob.save!
|
47
|
+
#bob = Person.create!(:name => 'bob')
|
48
|
+
|
49
|
+
puts Person.all.inspect
|
50
|
+
bob.destroy
|
51
|
+
puts Person.all.inspect
|
52
|
+
|
@@ -0,0 +1,149 @@
|
|
1
|
+
#~ bundle exec ruby story.rb
|
2
|
+
require 'rainbow' #https://github.com/sickill/rainbow
|
3
|
+
|
4
|
+
# :black => 0,
|
5
|
+
# :red => 1,
|
6
|
+
# :green => 2,
|
7
|
+
# :yellow => 3,
|
8
|
+
# :blue => 4,
|
9
|
+
# :magenta => 5,
|
10
|
+
# :cyan => 6,
|
11
|
+
# :white => 7,
|
12
|
+
# :default => 9,
|
13
|
+
|
14
|
+
#lesson 1
|
15
|
+
DEBUGV = true # help me debug the opengl complexities.
|
16
|
+
|
17
|
+
def pd(str)#debug notes - print if DEBUGV is active
|
18
|
+
puts ("" + str).center(80).underline.bright.background(:white).foreground(:red) if DEBUGV==true
|
19
|
+
end
|
20
|
+
|
21
|
+
def pg(str)
|
22
|
+
|
23
|
+
puts str.center(80).underline.bright.foreground(:white)
|
24
|
+
end
|
25
|
+
|
26
|
+
def pst(str)
|
27
|
+
|
28
|
+
puts ("STORY: " + str).underline.bright.foreground(:cyan)
|
29
|
+
end
|
30
|
+
def pau(str)
|
31
|
+
|
32
|
+
puts ("AUTHOR: " + str).underline.bright.foreground(:yellow)
|
33
|
+
end
|
34
|
+
|
35
|
+
pd "PLEASE NOTICE: to disable the RED NOTES - change DEBUGV to false"
|
36
|
+
pd "based on: http://www.ruby-doc.org/core/classes/Array.html"
|
37
|
+
pg "welcome to A simple story - I use it for self practicing Ruby"
|
38
|
+
pd 'Question : what is the different between single/double quotes? '
|
39
|
+
pd "Answer: in single quotes string: when interpter bump into the \\ sign \n- it takes the next char as it is, without executing it !"
|
40
|
+
pd 'Question : how to manipulate string by converting it to array first ?'
|
41
|
+
|
42
|
+
puts "#{"\n"*4}"
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
pg"0nce upon a time there was..."
|
49
|
+
|
50
|
+
|
51
|
+
age =0
|
52
|
+
pg "a pretty empty story.."
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
#tmp.to_a
|
59
|
+
#.rotate!
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
#make a string: "file" by manipulating string: life###
|
64
|
+
tmp = "life".split(//)
|
65
|
+
|
66
|
+
|
67
|
+
tmp = tmp.reverse
|
68
|
+
tmp = tmp.rotate(1)
|
69
|
+
tmp = tmp.join
|
70
|
+
######################################################
|
71
|
+
pd 'evaluate parameters within a string by using double quotes: "bla bla.. #{..param..}"'
|
72
|
+
pst "i have no life, nor a #{tmp}!"
|
73
|
+
pd 'HOW the string "life" becomes "file" ?'
|
74
|
+
|
75
|
+
pau "(laugh): but u r only #{age} seconds old !"
|
76
|
+
pst "right.. but the time is passing and i already #{age+=1} seconds old"
|
77
|
+
pd 'WHAT type is the parameter: age ?'
|
78
|
+
pau "remember: we get older - only when we have bad thoughts - think #{"possitive".upcase} !"
|
79
|
+
pd 'HOW to transform lower to upper case letters ?'
|
80
|
+
|
81
|
+
pst "i have no dog and certainly not a #{"dog".reverse} to be fullfilled with"
|
82
|
+
pd 'HOW to transform string: dog to god?'
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
pst "..think possitive..".+ "that's sound interesting -but how ?"
|
89
|
+
pau "think about the future - like where u want to be.. and slowly and carefully - start steping towards it"
|
90
|
+
pst "but i even don't know how to start the story.."
|
91
|
+
pst "please" + " tip me !" * (3)
|
92
|
+
|
93
|
+
|
94
|
+
pd 'BUT.. what if we multiply string with a negative integer ?
|
95
|
+
let\'s inspect the relevant function in the underlying C code : VALUE rb_str_times(VALUE str, VALUE times)
|
96
|
+
...if (len < 0) {
|
97
|
+
rb_raise(rb_eArgError, "negative argument");
|
98
|
+
}...'
|
99
|
+
pd "so let's make Ruby to catch our invalid operation and throw an error:"
|
100
|
+
begin
|
101
|
+
# eval string
|
102
|
+
pd "please" + " tip me !" * (-3)
|
103
|
+
rescue SyntaxError, NameError => boom
|
104
|
+
pd "String doesn't compile: " + boom.to_s
|
105
|
+
rescue StandardError => bang
|
106
|
+
pd "Error running script: " + bang.to_s
|
107
|
+
end
|
108
|
+
|
109
|
+
# difference
|
110
|
+
pau "for example: if u think to yourself"
|
111
|
+
ary = ["i","am","not".upcase,"smart","so","i","can","not".upcase,"do","it"]
|
112
|
+
|
113
|
+
pau ary.join(" ")
|
114
|
+
ary_possitive = ary - ["NOT"]
|
115
|
+
pau ary_possitive.join(" ")
|
116
|
+
pau "think possitive.."
|
117
|
+
ary_thinkp = "think possitive ??".split(//) # to split each word in a sentence use: / /
|
118
|
+
ary_thinkp.length.times do |i|
|
119
|
+
ary_thinkp[i].upcase! if i%2==0
|
120
|
+
end
|
121
|
+
pst ary_thinkp.join
|
122
|
+
pau "com'on.. just try !"
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
thought = [ "no", "way", "i", "can" ]
|
127
|
+
str = thought.join("--")
|
128
|
+
pst "ha! to switch my moto from: " + str
|
129
|
+
|
130
|
+
|
131
|
+
thought.collect! {|x| if x.length>2; x + "!"; else x end} #add ! to words longer than 2 chars.
|
132
|
+
|
133
|
+
str = thought.join(" ")
|
134
|
+
pst "to: " + str
|
135
|
+
pst "got it !"
|
136
|
+
#pst thought[0].to_s.chomp
|
137
|
+
############################################
|
138
|
+
pd "GOOD BYE !"
|
139
|
+
str = '\n good \n bye'
|
140
|
+
p str
|
141
|
+
puts str
|
142
|
+
str = "\n good \n bye"
|
143
|
+
p str
|
144
|
+
puts str
|
145
|
+
p "\tgoodbye\r\n".strip #=> "goodbye"
|
146
|
+
'tgoodgye'.gsub('g','b')
|
147
|
+
|
148
|
+
###########################end
|
149
|
+
|
data/story_with_ruby.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["ofer brown"]
|
10
10
|
s.email = ["brownman556@gmail.com"]
|
11
|
-
s.homepage = ""
|
11
|
+
s.homepage = "https://github.com/brownman/story_with_ruby"
|
12
12
|
s.summary = %q{learn ruby by composing a story}
|
13
13
|
s.description = %q{i use it for practicing ruby and rails}
|
14
14
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: story_with_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- ofer brown
|
@@ -26,8 +26,9 @@ dependencies:
|
|
26
26
|
description: i use it for practicing ruby and rails
|
27
27
|
email:
|
28
28
|
- brownman556@gmail.com
|
29
|
-
executables:
|
30
|
-
|
29
|
+
executables:
|
30
|
+
- active-record.rb
|
31
|
+
- strings_and_arrays.rb
|
31
32
|
extensions: []
|
32
33
|
|
33
34
|
extra_rdoc_files: []
|
@@ -36,10 +37,12 @@ files:
|
|
36
37
|
- .gitignore
|
37
38
|
- Gemfile
|
38
39
|
- Rakefile
|
40
|
+
- bin/active-record.rb
|
41
|
+
- bin/strings_and_arrays.rb
|
39
42
|
- lib/story_with_ruby.rb
|
40
43
|
- lib/story_with_ruby/version.rb
|
41
44
|
- story_with_ruby.gemspec
|
42
|
-
homepage:
|
45
|
+
homepage: https://github.com/brownman/story_with_ruby
|
43
46
|
licenses: []
|
44
47
|
|
45
48
|
post_install_message:
|