Rubyish 1.1.0

There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Rubyish --version 1.1.0
NuGet\Install-Package Rubyish -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rubyish" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rubyish --version 1.1.0
#r "nuget: Rubyish, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rubyish as a Cake Addin
#addin nuget:?package=Rubyish&version=1.1.0

// Install Rubyish as a Cake Tool
#tool nuget:?package=Rubyish&version=1.1.0

Rubyish

This library contains a bunch of things I wish were in .net from my rails days. It is not necessarily following good .net conventions but it does make writing some kinds of code more fun. If you choose to use .net in this fashion (lots of sending messages and dynamically calling methods) you are losing compiler protection. You have been warned

DateTime

var dt = new DateTime();

// Should return an int like 912312312 representing the time in seconds since the unix epoch
dt.ToTimeStamp(); 

// Converts this datetime object from EST to UTC
dt.EstToUtc(); 

// Converts this datetime object to EST
dt.ToEst(); 

// Get the start of the Day
DateTime.Now.StartOfDay();

// Get the end of the Day
DateTime.Now.StartOfDay();

Enumerable

var list = new List<string>();

// Returns True
list.Empty();

// Returns False
list.Add("IHAVEABIGSPOON");
list.Empty();

Object Interrogation

var obj = new Duck();
// See if this object has a certain property.  Returns true / false
obj.HasProperty("BeakColor");

// See if this object has a certain property.  Returns true / false
obj.RespondsTo("Quack");

// Return all the properties on this object.  Returns PropertyInfo[]
obj.Properties();

// Return all the methods on this object.  Returns MethodInfo[]
obj.Methods();

Json stuff

// Serialize this duck into a json string.  Returns JSON.
var obj = new Duck();
var json = Duck.ToJson();

// Deserialze this json string back into a duck.
var duckInJson = "{\"BeakColor\":\"Yellow\"}";
var duck = duckInJson.FromJson<Duck>();

Sending messages to objects

var duck = new Duck();

// Call the Quack method if its on the duck.
duck.Send("Quack");

// Call the Quack method and pass parameters to it.
duck.Send("Quack", "arg1", "arg2");

// If Quack returns a value you can get that value as well
var response = duck.Send<string>("Quack", "arg1", "arg2");

// If Duck has a BeakColor property with a getter
var response = duck.Send<string>("BeakColor");

// If Duck has a BeakColor property with a setter
duck.Send<string>("BeakColor", "Yellow");

// If Duck cannot respond to your message, then this throws a MethodMissingException
duck.Send<string>("DriveCar");

// If you want Duck to handle missing methods itself.  Here is an example that allows Duck to respond to anything starting with Quack.
    public class Duck : IMethodMissing
    {
        public string BeakColor { get; set; }

        public string Quack(string arg1, string arg2)
        {
            return "quack!!";
        }
        
        public object MethodMissing(string methodName, params object[] args)
        {
            if (methodName.StartsWith("Quack"))
            {
                var returnValue = methodName.Replace("Quack", "I know how to quack ");
                return returnValue;
            }
            throw new MethodMissingException($"I don't know what you mean");
        }
    }

var obj = new Duck();
// Writes out "I know how to quack Loudly"
Console.WriteLine(obj.Send<string>("QuackLoudly"));
// Writes out "I know how to quack Softly"
Console.WriteLine(obj.Send<string>("QuackSoftly"));

String methods

// Returns a boolean value true
string str = "True";
str.IsTrue();

// Returns a boolean value false
string str = "False";
str.IsTrue();

// Returns a boolean value false
string str = "false";
str.IsTrue();

// Returns a boolean value false
string str = "false";
str.IsTrue();

// Returns a boolean value false
string str = null;
str.IsTrue();

// Returns a boolean value false
string str = String.Empty;
str.IsTrue();

// Returns the boolean representation of this string
string str = "false";
str.ToBoolean();

// Returns a boolean value true if the string is anything other than empty or null
string str = "some value";
str.Present();

// Returns a boolean value true if the string is empty or null
string str = "some value";
str.Present();
// All of the following return timespan objects of the given length

// It's been one week since you looked at me
1.Weeks();
//Five days since you laughed at me saying Get that together, come back and see me"
5.Days();
//Three days (72 hours) since the living room
72.Hours();
// But it'll still be two days (2,880 Minutes) till I say I'm sorry
2880.Minutes();
// Cocked your head to the side and said, "I'm angry" (takes about 3 seconds)
3.Seconds();
// How many years ago this song came out
22.Years();
// How long this was a billboard top 1 hit
1.Months();
// Get an integer representation of a timespan in seconds.  Will return 60
1.Minutes().ToInt();

Times loops

// Will run your code x times.  In this instance value will be 10
var value = 0;
10.Times(() => { value += 1; });

// Collect results from a code run x.times.  Return and array that will look lke this [1,2,3,4,5,6,7,8,9,10]
int value = 0;
var returnValues = 10.Times<int>(() =>
{
    value += 1;
    return value;
});
// Assuming we have a type like Namespace.Duck, this will return true
Types.Exists("Duck");

// This will return the first type named Duck that we can find
Types.First("Duck");

// Assuming we have two ducks Namespace1.Duck and Namespace2.Duck this will return both types
Types.Find("Duck");

DateTime

var dt = new DateTime();

// Should return an int like 912312312 representing the time in seconds since the unix epoch
dt.ToTimeStamp(); 

// Converts this datetime object from EST to UTC
dt.EstToUtc(); 

// Converts this datetime object to EST
dt.ToEst(); 

Unix timespan stuff

// Create a datetime object given a unix timestamp
long ts = 946684800;
var dt = ts.FromUnixTimeStamp();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.1 629 6/23/2022