made a new section for programming posts
This commit is contained in:
parent
f28494de80
commit
2aac5f6b39
5 changed files with 97 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
layout: default
|
||||
---
|
||||
<div id="post">
|
||||
<div id="programming">
|
||||
{{ content }}
|
||||
</div>
|
61
_programming/2019-02-05-ruby2.6+-array#difference.markdown
Normal file
61
_programming/2019-02-05-ruby2.6+-array#difference.markdown
Normal file
|
@ -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 %}
|
||||
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
#### 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 %}
|
||||
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
#### 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!
|
|
@ -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
|
||||
|
|
|
@ -10,9 +10,17 @@ title: brendan mcdevitt
|
|||
<li><span>{{ post.date | date_to_string }}</span> » <a href="{{ post.url }}">{{ post.title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<h1>Homelab Posts</h1>
|
||||
<ul class="homelab">
|
||||
{% for post in site.homelab %}
|
||||
<li><span>{{ post.date | date_to_string }}</span> » <a href="{{ post.url }}">{{ post.title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<h1>Programming</h1>
|
||||
<ul class="programming">
|
||||
{% for post in site.programming %}
|
||||
<li><span>{{ post.date | date_to_string }}</span> » <a href="{{ post.url }}"> {{post.title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
Loading…
Add table
Reference in a new issue