Thursday 5/2 Meetup

6 views
Skip to first unread message

Benjamin Oakes

unread,
Apr 25, 2013, 2:37:47 PM4/25/13
to ic-...@googlegroups.com
Hi all,

The next ICRuby meetup is coming up on Thursday, May 2nd.  The lightning talks turned out really well last month, so let's do some more!  If you're interested in presenting something for 5 minutes, please let the group know in a reply.  :)

I'm thinking I'm going to show a cool `gsub` trick I use sometimes.

If you're new to the group, you can find more info about our meeting schedule and location on our website:  http://www.icruby.org

See you then,

Ben

--

Sam Beran

unread,
Apr 25, 2013, 5:14:58 PM4/25/13
to ic-...@googlegroups.com
I can talk about Travis-CI.
--
 
---
You received this message because you are subscribed to the Google Groups "Iowa City Ruby Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ic-ruby+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Benjamin Oakes

unread,
May 1, 2013, 2:43:17 PM5/1/13
to ic-...@googlegroups.com
Hi all,

Just a reminder that the meetup is tomorrow in the normal room.

Thanks for offering to talk, Sam!  Any other takers?

See you tomorrow,

Ben

Sam Beran

unread,
May 1, 2013, 2:47:10 PM5/1/13
to ic-...@googlegroups.com
Hey Ben,

Unfortunately I have to go to Minnesota tomorrow so I can't make it :( If someone else wants to talk travis I wouldn't be offended, or I can talk about it next month.

Sam

geemus (Wesley Beary)

unread,
May 1, 2013, 3:19:49 PM5/1/13
to ic-...@googlegroups.com
Hey, I can present, something! I just don't know exactly what yet...

Benjamin Oakes

unread,
May 2, 2013, 9:50:26 AM5/2/13
to ic-...@googlegroups.com
No worries, we'll catch you next time!

Benjamin Oakes

unread,
May 2, 2013, 9:51:52 AM5/2/13
to ic-...@googlegroups.com
Sounds good.  Thanks, Wes!

If anyone else has something they'd like to talk about for a few minutes, please feel free!  No materials necessary, just a topic.  :)

Ben

Nathan L Smith

unread,
May 2, 2013, 10:11:21 AM5/2/13
to ic-...@googlegroups.com

Benjamin Oakes

unread,
May 2, 2013, 2:41:28 PM5/2/13
to ic-...@googlegroups.com
Thanks for coming by, everyone; it was a good meetup.

If you couldn't make it, this is approximately what I presented:  https://github.com/benjaminoakes/pencil_mustache/blob/master/lightning_talk.md

Did you have any links to docs on Pry, Joe?  There are several features you showed I'd like to remember in the future.

See you next time,

Ben

Jordan Running

unread,
May 2, 2013, 3:41:37 PM5/2/13
to ic-...@googlegroups.com
That's a neat feature, Ben, but while the syntax isn't quite as pretty you can do this with Kernel#sprintf (with all of its nice formatting features):

irb> template = "%{foo} is about %.2<bar>f"
irb> sprintf(template, foo, bar: Math::PI)
=> "π is about 3.14"

Or just:

"%{foo} is about %.2<bar>f" % { foo: , bar: Math::PI }

(%{foo} (note the curly braces) is equivalent to %<foo>s and doesn't take formatting options.)

Obviously this feature doesn't do you any favors wrt readability and if you abuse it your team will murder you in your sleep.

Jordan

P.S. Maybe writing a tiny template library is one of those itches every developer has to scratch once. Some of the very first code I pushed to GitHub was this, which abuses Kernel#bindinghttps://github.com/jrunning/StupidLittleTemplate
 ⚡ Email or IM me at jrun...@gmail.com
 ⚡ Tweet me at @swirlee
 ⚡ Text me at (925) 567-3267

Benjamin Oakes

unread,
May 2, 2013, 9:21:15 PM5/2/13
to ic-...@googlegroups.com
Interesting, I knew the C-like uses of sprintf (like %s), but I didn't know you could pass a hash like you mention.  Thanks for sharing!  It's definitely a good option if that fits your use case.

I've considered doing something like that with eval before, but that gets really scary really fast.

There are so many ways to do this type of thing in Ruby.  I didn't know you could leave out "{}" in string interpolation for a long time:

    # Example from your README
    @name = 'Alice'
    $age ='29'
    puts "My name is #@name and I'm #$age years old"

It comes up pretty rarely for me, since it doesn't work with locals or anything other than just a single identifier.  Of course, it's not too useful if you're reading the string from a file, etc.

Since there are so many ways to do simple templates in a line or two in Ruby, it makes me wonder how you can do this elegantly in JavaScript without an external library like Handlebars or Mustache.

   var tmpl = 'My name is {{name}} and I'm {{age}} years old';
   tmpl.something({ name: 'Alice', age: 29 }); // => "My name is Alice and I'm 29 years old"

Anyone have tricks up their sleeves?

Ben

Jordan Running

unread,
May 2, 2013, 9:59:16 PM5/2/13
to ic-...@googlegroups.com
I always forget about that string interpolation syntax.

I can't think of a good way to do similar in JavaScript, but ES6 has template strings: https://github.com/dherman/tc39-codex-wiki/blob/master/data/es6/template-strings/index.md (The "tagged template strings" are interesting—here's an example: https://gist.github.com/kitcambridge/5025658.)

And of course CoffeeScript has string interpolation just like Ruby's (well, except the curly braces are always required).

Jordan

Reply all
Reply to author
Forward
0 new messages