DevHeads.net

Postings by Brandon Weaver

Qo 0.5.0 API

*What's Qo?*

Qo is a pattern matching implementation in pure Ruby.

It lets you do things like this:

Qo.case(['Foo', 42]) { |m|
m.when(/^F/, Any) { 'Foo!' }
m.else { 'Not foo...' }
}
=> 'Foo!'

[['Foo', 42], ['Bar', 24]].map(&Qo.match { |m|
m.when(/^F/, Any) { 'Foo!' }
m.else { 'Not foo...' }
})
=> ['Foo!', 'Not foo...']

The syntax purposely mimics case statements.

*RFC*

Working on refining the API for Qo, mostly modeled after the 2.6+ potential
Hash#=== and Array#=== features. If these two are merged, Qo will likely
get substantially faster.

Qo 0.4.0 released

<a href="https://github.com/baweaver/qo" title="https://github.com/baweaver/qo">https://github.com/baweaver/qo</a>

Qo v0.4.0 released!

Changes:

* Wildcard replaced with the Any gem: <a href="https://github.com/baweaver/any" title="https://github.com/baweaver/any">https://github.com/baweaver/any</a>
* New logo

Example:

Qo[:*, :*] === [1, 1]
Qo[name: :*] === {id: 1, name: 'foo'}

now becomes

Qo[Any, Any] === [1, 1]
Qo[name: Any] === {id: 1, name: 'foo'}

Going to attempt to reconcile against the Array and Hash === proposals in
core at the moment:

[Any, Any] === [1, 1]
{name: Any} === {id: 1, name: 'foo'}

Expect more releases in the near future as we approach a solid v1 api.

Qo 0.3.0 released

Qo 0.3.0 is now out, and comes with a shiny new way to do pattern matching:

<a href="https://github.com/baweaver/qo" title="https://github.com/baweaver/qo">https://github.com/baweaver/qo</a>

name_longer_than_three = -> person { person.name.size > 3 }
people_with_truncated_names = people.map(&Qo.match { |m|
m.when(name_longer_than_three) { |person|
Person.new(person.name[0..2], person.age) }
m.else(&:itself)
})
# And standalone like a case:Qo.match(people.first) { |m|
m.when(age: 10..19) { |person| "#{person.name} is a teen that's
#{person.age} years old" }
m.else { |person| "#{person.name} is #{person.age} years old" }
}

A bit more Scala inspired, and defini

Exploring FP in Ruby

I've been writing a few more advanced articles on how base concepts of Ruby
can be utilized to emulate features of more functionally oriented
languages.

Xf 0.1.0 - Transform Functions

Back again with new toys after playing with Rambda in Javascript again, and
wanting to keep a few of the features for later.

<a href="https://github.com/baweaver/xf" title="https://github.com/baweaver/xf">https://github.com/baweaver/xf</a>

Introducing Xf, or Transform Functions. The idea behind this one was to
emulate lenses from functional languages in Ruby in a pragmatic way with a
bit of a Ruby twist.

Deal with a lot of JSON and transforming it? Have no idea where the key is,
or even if it's in the same place? Xf is great with that, give it a shot!

Was tempted to add some of this to Qo, but the concerns were fairly
seperate.

Enjoy!

- baweaver

Qo 0.1.6 released - RHA pattern matching added

<a href="https://github.com/baweaver/qo" title="https://github.com/baweaver/qo">https://github.com/baweaver/qo</a>

Added a feature for pattern matching with right hand assignment using a
guarded block implementation.

Qo (0.1.1) released

First release of Qo, short for Query Object.

Illustrated Guide to Ruby

Hey all, I'm working on a new book: An Illustrated Guide to Ruby. Havenwood
is helping me write as well.

<a href="https://baweaver.gitbooks.io/an-illustrated-guide-to-ruby/content/" title="https://baweaver.gitbooks.io/an-illustrated-guide-to-ruby/content/">https://baweaver.gitbooks.io/an-illustrated-guide-to-ruby/content/</a>

Short version: I'm using cute Lemurs to teach Ruby.

Currently it's my NaNoWriMo project, but a long term idea of mine I wanted
to fully realize. After reading books like Learn You a Haskell and Why's
Poignant Guide I wanted to write a true beginners book for Ruby.

The illustrations take a bit to catch up as they take ~20-30m each
including digitalization, though I'm getting faster.

Daily Reminder: TCL > Ruby 19927

shoutz to irc.gangnet.ru #tclmafia 1304

Daily Reminder: TCL > Ruby 11116

shoutz to irc.gangnet.ru #tclmafia 28528

Daily Reminder: TCL > Ruby 22043

shoutz to irc.gangnet.ru #tclmafia 16155

Daily Reminder: TCL > Ruby 6972

shoutz to irc.gangnet.ru #tclmafia 23762

Daily Reminder: TCL > Ruby 8110

shoutz to irc.gangnet.ru #tclmafia 8905

Daily Reminder: TCL > Ruby 20558

shoutz to irc.gangnet.ru #tclmafia 3869

Daily Reminder: TCL > Ruby 28462

shoutz to irc.gangnet.ru #tclmafia 28265

Daily Reminder: TCL > Ruby 26812

shoutz to irc.gangnet.ru #tclmafia 21949

Daily Reminder: TCL > Ruby 8127

shoutz to irc.gangnet.ru #tclmafia 23288

Daily Reminder: TCL > Ruby 1476

shoutz to irc.gangnet.ru #tclmafia 10060

Izzy - Condense long conditionals

Izzy lets you condense long conditionals into more terse code.

<a href="https://github.com/baweaver/izzy" title="https://github.com/baweaver/izzy">https://github.com/baweaver/izzy</a>

So let's see it in action: (Person class is in the readme)

brandon = Person.new('brandon', 23, 'm')

# Boolean matchers
brandon.all_of? :older_than_18?, :male?, :me?, :geek? # => true
brandon.none_of? :younger_than_18?, :female? # => true
brandon.any_of? :male?, :female?, :geek? # => true

# === matchers
brandon.matches_all? name: /^br/, age: (20..30) # => true
brandon.matches_any? name: /br$/, age: (20..30) # => true
brandon.matches_none?

New Array Methods idea

So granted I've ventured over to Lisp land a bit, but these ideas still
seem like they could be useful:

array = [1, 2, 3, 4, 5]

# Exists
array.first # => 1

# Proposed
array.rest # => [2, 3, 4, 5]
# ...and/or array.tail

Granted it would be as simple as array[1..-1] but that lacks the distinct
eloquence of most ruby syntax and it seems to be far more of a language
feature possibility.

Monkey patching it on would be trivial, yes, but I would rather avoid that
in favor of discussing this as a possible feature.

This of course inspired by Lisp's car/cdr or first/rest and head/tail (of
which I

Mime

Hey Ruby-Talk,

Working on a project that I'd like to get some feedback on:
<a href="https://github.com/baweaver/mime" title="https://github.com/baweaver/mime">https://github.com/baweaver/mime</a>

While working on showing some newer technicians how I did things, I
realized that I should really automate these tasks. I then took to making a
script to do this, and halfway through thought to myself why in the world
am I doing this? By showing them the steps I'd already done the task, why
rewrite the entire thing?

Pure Ruby Jobs

One thing has been bugging me lately. I've been looking around for jobs in
Ruby and I always find Rails within minutes, but pure Ruby or Raw Ruby are
never really mentioned. I just find it odd that Rails completely dominates
the Ruby market when quite frankly Ruby itself is an excellent language for
administration on its own. I can understand it falling under "a scripting
language" in most markets like Python or Perl, but given its strengths why
doesn't it stand more on its own outside of large scale DSLs?

numeric?

I've found a bit of an annoyance trying to find out if a number is numeric
or not. I thought it would probably be a simple string method but I found
far more contrived solutions like regex matches. Eventually I settled on
monkey patching string with a Numeric? method using Float(self)! = nil
rescue false.

Is there a better way to go about this? If not, can we get something added
to the core?

Thanks for your time,

Brandon

Ruby Conferences for Students

I'd love to be able to go to a Ruby conference, but 350$ is somewhat
outside my price range as a full time student. Are there any
programs available for students to get a discount to attend such meetings?

Thanks for your time,

Brandon Weaver

Teaching a Class on Ruby

Hey guys, I'm new to the list. I'm a Student Rubyist/Unix Hacker out of
Joplin, MO.

I'm looking into starting a Class/Podcast on Ruby because of some of the
interest I've generated in the language. I've been asked if I could show
various sets of people (approx 15) how to program in Ruby, so instead of
individually teaching each one I've decided to host a class of sorts. Some
of those interested have experience in .NET and Java, while others haven't
ever touched programming.