Skip to content

Commit

Permalink
Add final updates to notebook and add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
alkrauss48 committed Jun 11, 2015
1 parent 538ebf7 commit cf7b520
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}
},
"source": [
"Yes, but *metaprogramming* typically refers to something else in **Ruby**"
"Yes, but metaprogramming typically refers to something else in **Ruby**"
]
},
{
Expand Down Expand Up @@ -127,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 46,
"execution_count": 1,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -171,7 +171,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 2,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -216,7 +216,7 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": 3,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -256,7 +256,7 @@
}
},
"source": [
"The method Array#replace method already exists, and it swaps out the entire array with another array that you provide as an arg. We just overwrote that method."
"The Array#replace method already exists, and it swaps out the entire array with another array that you provide as an arg. We just overwrote that method."
]
},
{
Expand Down Expand Up @@ -303,7 +303,7 @@
"Key things of note here:\n",
" \n",
"* Instantiated objects have a class of **MyClass** \n",
"* MyClass - also an object - has a class of **Class**\n",
"* MyClass has a class of **Class** and is also an object\n",
"* While MyClass has a class of Class, it inherits from **Object**"
]
},
Expand Down Expand Up @@ -418,7 +418,7 @@
},
{
"cell_type": "code",
"execution_count": 49,
"execution_count": 4,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -471,7 +471,7 @@
},
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 5,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -529,7 +529,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 7,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -554,7 +554,7 @@
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": 8,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -568,14 +568,14 @@
"\n",
"class OKCRB\n",
" def is_boss?\n",
" puts \"true\"\n",
" true\n",
" end\n",
"end\n",
"\n",
"# New Code\n",
"\n",
"okcrb = OKCRB.new\n",
"okcrb.send(\"is_boss?\")"
"puts okcrb.send(\"is_boss?\")"
]
},
{
Expand Down Expand Up @@ -604,7 +604,7 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 9,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -647,7 +647,7 @@
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": 11,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -668,7 +668,7 @@
"\n",
"b = Book.new\n",
"b.read\n",
"# b.read('a', 'b') { \"foo\" }"
"b.read('a', 'b') { \"foo\" }"
]
},
{
Expand Down Expand Up @@ -790,7 +790,7 @@
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 12,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -825,7 +825,7 @@
},
{
"cell_type": "code",
"execution_count": 56,
"execution_count": 14,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -839,11 +839,18 @@
"\n",
"# the dynamic way\n",
"Book = Class.new do\n",
" def foo\n",
" \"foo!\"\n",
" end\n",
" \n",
" #Both method declaration types work\n",
" \n",
" define_method('title') do\n",
" \"All My Friends Are Dead\"\n",
" end\n",
"end\n",
"\n",
"puts Book.new.foo\n",
"puts Book.new.title"
]
},
Expand Down Expand Up @@ -871,7 +878,7 @@
},
{
"cell_type": "code",
"execution_count": 57,
"execution_count": 19,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -888,6 +895,7 @@
"MyClass = Class.new do\n",
" \"#{my_var} in the class definition\"\n",
" \n",
" # Have to use dynamic method creation to access my_var\n",
" define_method :my_method do\n",
" \"#{my_var} in the method\"\n",
" end\n",
Expand Down Expand Up @@ -931,7 +939,7 @@
},
{
"cell_type": "code",
"execution_count": 58,
"execution_count": 20,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -1011,7 +1019,7 @@
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": 22,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -1034,7 +1042,7 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": 24,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -1047,7 +1055,7 @@
"%%ruby\n",
"\n",
"def proc_example\n",
" p = proc {|x,y| return x*y }\n",
" p = proc {|x,y| return x*y }\n",
" result = p.call(2, 4) * 10\n",
" return result\n",
"end\n",
Expand Down Expand Up @@ -1127,7 +1135,7 @@
},
{
"cell_type": "code",
"execution_count": 61,
"execution_count": 26,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -1178,7 +1186,7 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": 28,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -1191,6 +1199,7 @@
"%%ruby\n",
"\n",
"def add_method_to(a_class)\n",
"\n",
" a_class.class_eval do\n",
" def m; 'Hello!'; end\n",
" end\n",
Expand Down Expand Up @@ -1237,7 +1246,7 @@
},
{
"cell_type": "code",
"execution_count": 63,
"execution_count": 29,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -1268,7 +1277,7 @@
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": 32,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -1283,7 +1292,7 @@
"klass = \"Book\"\n",
"instance_var = \"title\"\n",
"\n",
"eval <<-CODE\n",
"eval <<-CODE # This is just a multi-line string\n",
" class #{klass}\n",
" attr_accessor :#{instance_var}\n",
"\n",
Expand Down Expand Up @@ -1321,7 +1330,7 @@
},
{
"cell_type": "code",
"execution_count": 65,
"execution_count": 34,
"metadata": {
"collapsed": false,
"slideshow": {
Expand All @@ -1339,7 +1348,7 @@
" puts eval code\n",
"end\n",
"\n",
"explore_array(\"find_index('b')\")\n",
"explore_array(\"find_index('c')\")\n",
"\n",
"# explore_array(\"object_id; Dir.glob('*')\")"
]
Expand Down Expand Up @@ -1368,7 +1377,7 @@
},
{
"cell_type": "code",
"execution_count": 66,
"execution_count": 35,
"metadata": {
"collapsed": false,
"slideshow": {
Expand Down Expand Up @@ -1418,7 +1427,7 @@
"source": [
"# Thanks!\n",
"\n",
"@thecodeboss\n",
"[@thecodeboss](https://twitter.com/thecodeboss/)\n",
"\n",
"https://github.com/alkrauss48\n",
"\n",
Expand Down
Loading

0 comments on commit cf7b520

Please sign in to comment.