diff --git a/_config.yml b/_config.yml index b1fa03e..3d31747 100644 --- a/_config.yml +++ b/_config.yml @@ -29,6 +29,8 @@ theme: minima collections: homelab: output: true + programming: + output: true # Exclude from processing. # The following items will not be processed, by default. Create a custom list diff --git a/_layouts/post.html b/_layouts/programming.html similarity index 66% rename from _layouts/post.html rename to _layouts/programming.html index 0b28e6b..77d7448 100644 --- a/_layouts/post.html +++ b/_layouts/programming.html @@ -1,6 +1,6 @@ --- layout: default --- -
+
{{ content }}
diff --git a/_programming/2019-02-05-ruby2.6+-array#difference.markdown b/_programming/2019-02-05-ruby2.6+-array#difference.markdown new file mode 100644 index 0000000..329f53d --- /dev/null +++ b/_programming/2019-02-05-ruby2.6+-array#difference.markdown @@ -0,0 +1,61 @@ +--- +layout: programming +title: "Ruby 2.6+ Array#Difference" +date: 2019-02-05 +categories: programming +--- + +# Array#Difference - [Array#Difference](https://github.com/ruby/ruby/blob/trunk/array.c#L4450-L4563) +I wanted to do a quick post on a new method added to ruby Array class in version 2.6. I just learned about this over the past weekend. +This will quickly grow to be a favorite of mine. + +A method to check differences in values between two arrays. + +#### Make arrays abc and abcdef + +{% highlight ruby %} +[1] pry(main)> abc = ['a','b','c'] +=> ["a", "b", "c"] + +[2] pry(main)> abcdef = 'a', 'b', 'c', 'd', 'e', 'f' +=> ["a", "b", "c", "d", "e", "f"] +{% endhighlight %} + + +
+ + +#### ruby 2.5 +In versions prior, I would make a .difference method in my .pryrc file and that +will be loaded at runtime when I run my console. You can also monkey patch it +live in a pry console. Found this via +[stackedoverflow](https://stackoverflow.com/questions/8639857/rails-3-how-to-get-the-difference-between-two-arrays) +post. Here is how I would add it in a running pry session: + +{% highlight ruby %} +[17] pry(main)> class Array +[17] pry(main)* def difference(a) +[17] pry(main)* self - a | a - self +[17] pry(main)* end +[17] pry(main)* end +=> :difference + +[26] pry(main)> abcdef.difference(abc) +=> ["d", "e", "f"] + +{% endhighlight %} + + +
+ + +#### ruby 2.6 +But now in ruby 2.6+, you can just use the .difference method. It is built into +the class now. + +{% highlight ruby %} +[3] pry(main)> abcdef.difference(abc) +=> ["d", "e", "f"] +{% endhighlight %} + +so nice, so easy! diff --git a/css/screen.css b/css/screen.css index cf4acca..67488f8 100644 --- a/css/screen.css +++ b/css/screen.css @@ -51,12 +51,19 @@ table { font: 100%; } +hr { + margin-top: 10px; + margin-bottom: 10px; +} + + /*****************************************************************************/ /* /* Home /* /*****************************************************************************/ +# posts ul.posts { list-style-type: none; margin-bottom: 2em; @@ -72,6 +79,7 @@ ul.posts { font-size: 80%; } +# homelab ul.homelab { list-style-type: none; margin-bottom: 2em; @@ -87,6 +95,23 @@ ul.homelab { font-size: 80%; } + +# programming +ul.programming { + list-style-type: none; + margin-bottom: 2em; +} + + ul.programming li { + line-height: 1.75em; + } + + ul.programming span { + color: #aaa; + font-family: Monaco, "Courier New", monospace; + font-size: 80%; + } + /*****************************************************************************/ /* /* Site diff --git a/index.html b/index.html index 918401f..830d610 100644 --- a/index.html +++ b/index.html @@ -10,9 +10,17 @@ title: brendan mcdevitt
  • {{ post.date | date_to_string }} » {{ post.title }}
  • {% endfor %} +

    Homelab Posts

    + +

    Programming

    +