Tag: extension methods

  • Another useful collection method? Enumerable#select_first

    For a personal project I’m working on, I need to find out the smallest time period with more than 5 records. I essentially wrote this code: period = [1.week, 1.month, 1.year].select_first do |period| Record.where(“published_at >= ?”, period.ago).count >= 5 end only to find out that the select_first method doesn’t exist. So I wrote it: module…

  • Formating strings in C#, like in Python

    I like Python’s way to format strings because you can use it everywhere, it’s part of the strings. You can do print(“Welcome %s!” % user.name) as you can do Console.Writeln(“Welcome {0}!”, user.Name) But then in Python you can also do randomMethodThatTakesAString(“Welcome %s!” % user.name) In C# it gets trickier, because the call to Console.Writeln takes…