Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the Dictionary#clear script function #6508

Merged
merged 1 commit into from Aug 2, 2018

Conversation

gunnarbeutner
Copy link
Contributor

This adds a new user-accessible method to the Dictionary class: clear

Like the name suggests this method removes all items from a dictionary.

@gunnarbeutner gunnarbeutner added enhancement New feature or request area/configuration DSL, parser, compiler, error handling labels Aug 2, 2018
@gunnarbeutner
Copy link
Contributor Author

gunnar@abyss ~/icinga2 (feature/dictionary-clear) $ icinga2 console
Icinga 2 (version: v2.8.4-797-g73f69e89d)
Type $help to view available commands.
<1> => d = { a = 3, b = 5, c = 7 }
null
<2> => d
{
	a = 3.000000
	b = 5.000000
	c = 7.000000
}
<3> => d.clear()
null
<4> => d
{
}
<5> =>

@Crunsher
Copy link
Contributor

Crunsher commented Aug 2, 2018

What's the advantage of this over d = {}?

@gunnarbeutner
Copy link
Contributor Author

d = {} creates a new dictionary, if there are references to the old dictionary elsewhere (e.g. because a reference to the dictionary was stored in a different variable) those other references will be unaffected by that change.

@dnsmichi
Copy link
Contributor

dnsmichi commented Aug 2, 2018

We already have Array#clear, so I'm fine with it.

@dnsmichi dnsmichi added this to the 2.10.0 milestone Aug 2, 2018
@dnsmichi dnsmichi self-requested a review August 2, 2018 08:23
Copy link
Contributor

@Crunsher Crunsher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<2> => d = {a=5, b={f=2, a=1} }
null
<3> => d
{
	a = 5.000000
	b = {
		a = 1.000000
		f = 2.000000
	}
}
<4> => d.b
{
	a = 1.000000
	f = 2.000000
}
<5> => d.b.clear()
null
<6> => d
{
	a = 5.000000
	b = {
	}
}
<7> => d.clear()
null
<8> => d
{
}

@Crunsher Crunsher merged commit 065bc23 into Icinga:master Aug 2, 2018
@gunnarbeutner gunnarbeutner deleted the feature/dictionary-clear branch August 2, 2018 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/configuration DSL, parser, compiler, error handling enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants